2017-07-21 76 views
0

我用CSS創建了兩個相同大小的圓。通過編碼,桌面屏幕上的輸出很好。但是當我在手機上查看輸出時,該圓圈重疊。我聽說大衆汽車部門對於響應式頁面設計非常有用。這就是我使用大衆汽車的原因。任何其他技術也歡迎。如何使用vw單位在css中創建響應式圈子?

HTML:

<div class="circle1"> Hello I am a Circle1 </div> 
    <div class="circle2"> Hello I am a Circle2 </div> 

CSS:

.circle1 
    { 
    width:100px; 
    height: 100px; 
    border-radius: 50%; 
    font-size: 10px; 
    color:#F7FAF7; 
    line-height: 100px; 
    text-align: center; 
    background:#000; 
    position: fixed; 
    top: 0vh; 
    left: 0vw; 
    }  
.circle2 
    { 
    width:100px; 
    height: 100px; 
    border-radius: 50%; 
    font-size: 10px; 
    color:#F7FAF7; 
    line-height: 100px; 
    text-align: center; 
    background:#000; 
    position: fixed; 
    top: 0vh; 
    left: 8vw; 
    } 
+0

你可以讓你嘗試在臺式機和移動完成什麼草圖? – murb

+0

我需要幾個相隔一定距離的圓圈。現在我只用了兩圈。 – nawas

+0

是固定義務嗎? –

回答

0

這個問題是非常開放式的,當你在代碼中寫的是什麼取決於你想要什麼。

如果你正在尋找一排圈子,也許你應該使用浮動。 如果該行中沒有足夠的空間,它將導致您的圈子在下一行中移動。而且,它在所有設備上看起來不錯,因爲沒有任何重疊或縮小。

樣品:

.circle { 
 
    width: 100px; 
 
    height: 100px; 
 
    border-radius: 50%; 
 
    font-size: 10px; 
 
    color: #F7FAF7; 
 
    line-height: 100px; 
 
    text-align: center; 
 
    background: #000; 
 
    float: left; 
 
    margin: 5px; 
 
    padding: 5px; 
 
}
<div class="circle"> Hello I am a Circle1 </div> 
 
<div class="circle"> Hello I am a Circle2 </div> 
 
<div class="circle"> Hello I am a Circle3 </div> 
 
<div class="circle"> Hello I am a Circle4 </div>

如果你正在尋找一箇中心圓周圍有對齊所有其他圈子裏,也許相對位置比較好。但是這看起來不像在移動設備上看起來不錯的那種設計。

樣品:

body { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
.main { 
 
    position: relative; 
 
    width: 100px; 
 
    height: 100px; 
 
    border-radius: 50%; 
 
    font-size: 10px; 
 
    color: #F7FAF7; 
 
    line-height: 100px; 
 
    text-align: center; 
 
    background: #abf; 
 
    left: 200px; 
 
    top: 200px; 
 
} 
 

 
.circle { 
 
    position: absolute; 
 
    width: 100px; 
 
    height: 100px; 
 
    border-radius: 50%; 
 
    font-size: 10px; 
 
    color: #F7FAF7; 
 
    line-height: 100px; 
 
    text-align: center; 
 
    background: #456; 
 
} 
 

 
.pos1 { 
 
    top: 120px; 
 
    left: 0px; 
 
} 
 

 
.pos2 { 
 
    top: -120px; 
 
    left: 0px; 
 
} 
 

 
.pos3 { 
 
    top: 0px; 
 
    left: 120px; 
 
} 
 

 
.pos4 { 
 
    top: 0px; 
 
    left: -120px; 
 
}
<div class="main"> 
 
    Main circle 
 
    <div class="circle pos1"> Hello I am a Circle1 </div> 
 
    <div class="circle pos2"> Hello I am a Circle2 </div> 
 
    <div class="circle pos3"> Hello I am a Circle3 </div> 
 
    <div class="circle pos4"> Hello I am a Circle4 </div> 
 
</div>