2017-02-20 14 views
0

9つの円からなる反応性の高いページを作成したいと思います。以下のコードでは、ブラウザのサイズを変更するたびにサークルの位置が変更されます(応答しません)。私はCSSの@メディアのクエリを使用してみましたが、私は応答して作成できませんでした。ウェブページの反応円の作成

固定幅100pxの代わりに、位置の幅、高さに%を使用する必要がありますか?

<html> 
<head> 
<style> 
.circle1{ 
    width:100px; 
    height:100px; 
    margin-left:600px; 
    background-color:black; 
    border-radius:100px; 
} 
.circle2{ 
    margin-left:600px; 
    margin-top:30%; 
    width: 100px; 
    height:100px; 
    background-color:darkred; 
    border-radius:100px; 
} 
.circle3{ 
    margin-left:250px; 
    margin-top:-27%; 
    width: 100px; 
    height:100px; 
    background-color:gold; 
    border-radius:100px; 
} 
.circle4{ 
    margin-top:-20%; 
    margin-left:350px; 
    width:100px; 
    height:100px; 
    background-color:greenyellow; 
    border-radius:100px; 
} 
.circle5{ 
    margin-left:63%; 
    margin-top:-8%; 
    width: 100px; 
    height:100px; 
    background-color:blueviolet; 
    border-radius:100px; 
} 
.circle6{ 
    margin-left:900px; 
    margin-top:5%; 
    width: 100px; 
    height:100px; 
    background-color:deeppink; 
    border-radius:100px; 
*emphasized text* 
} 
.circle7{ 
    margin-left:350px; 
    margin-top:7%; 
    width: 100px; 
    height:100px; 
    background-color:blue; 
    border-radius:100px; 
} 
.circle8{ 
    margin-left:800px; 
    margin-top:-10%; 
    width : 100px; 
    height:100px; 
    background-color:aqua; 
    border-radius:100px; 
} 
.circle9{ 
    margin-left:600px; 
    margin-top:-20%; 
    width: 100px; 
    height:100px; 
    background-color:darkorange; 
    border-radius:100px; 
} 
</style> 
</head> 
<body> 
    <div class="circle1"></div> 
    <div class="circle2"></div> 
    <div class="circle3"></div> 
    <div class="circle4"></div> 
    <div class="circle5"></div> 
    <div class="circle6"></div> 
    <div class="circle7"></div> 
    <div class="circle8"></div> 
    <div class="circle9"></div> 
</body> 
</html> 
+0

nデスクトップ/タブレット/モバイル? –

+0

私はラップトップでmozillaブラウザの開発者モードで画面のサイズを横方向に変更しています。予想される結果は、中央に1円、その周りに8つの円が残ります。 – vineeth

+1

[センタリングされたコンテンツのあるレスポンシブルサークル](http://stackoverflow.com/questions/34788537/responsive-circle-with-centered-content)の可能な複製 –

答えて

1

ここではコードです:あなたは9円が私になりたいん位置

.full{ margin:0 auto; width:70%;} 
 
.circle1{ 
 
    width: 15%; 
 
    padding-top: 15%; 
 
    margin:0 42%; 
 
    background-color: black; 
 
    border-radius: 50%; 
 
\t display:inline-block; 
 
} 
 
.circle2{ 
 
    width: 15%; 
 
    padding-top: 15%; 
 
    margin-left: 20%; 
 
    background-color:darkred; 
 
    border-radius: 50%; 
 
\t display:inline-block; 
 
\t margin-top:20px; 
 
} 
 
.circle3{ 
 
    width: 15%; 
 
    padding-top: 15%; 
 
    margin-left: 26%; 
 
    background-color:gold; 
 
    border-radius: 50%; 
 
\t display:inline-block; 
 
\t margin-top:20px; 
 
\t margin-right: 15%; 
 
} 
 
.circle4{ 
 
    width: 15%; 
 
    padding-top: 15%; 
 
    margin-left: 0%; 
 
    background-color:greenyellow; 
 
    border-radius: 50%; 
 
\t display:inline-block; 
 
\t margin-top:20px; 
 
} 
 
.circle5{ 
 
    width: 15%; 
 
    padding-top: 15%; 
 
    margin-left: 26%; 
 
    background-color:blueviolet; 
 
    border-radius: 50%; 
 
\t display:inline-block; 
 
\t margin-top:20px; 
 
} 
 
.circle6{ 
 
     width: 15%; 
 
    padding-top: 15%; 
 
    margin-left: 26%; 
 
    background-color:deeppink; 
 
    border-radius: 50%; 
 
\t display:inline-block; 
 
\t margin-top:20px; 
 
} 
 
.circle7{ 
 
     width: 15%; 
 
    padding-top: 15%; 
 
    margin-left: 20%; 
 
    background-color:blue; 
 
    border-radius: 50%; 
 
\t display:inline-block; 
 
\t margin-top:20px; 
 
} 
 
.circle8{ 
 
    width: 15%; 
 
    padding-top: 15%; 
 
    margin-left: 26%; 
 
    background-color:aqua; 
 
    border-radius: 50%; 
 
    display: inline-block; 
 
    margin-top: 20px; 
 
} 
 
.circle9{ 
 
    width: 15%; 
 
    padding-top: 15%; 
 
    margin: 0 42%; 
 
    background-color:darkorange; 
 
    border-radius: 50%; 
 
    display: inline-block; 
 
} 
 
@media only screen and (max-width: 980px) { 
 
\t .full{width:100%;} 
 
}
<div class="full"> 
 
\t <div class="circle1"></div> 
 
    <div class="circle2"></div> 
 
    <div class="circle3"></div> 
 
    <div class="circle4"></div> 
 
    <div class="circle5"></div> 
 
    <div class="circle6"></div> 
 
    <div class="circle7"></div> 
 
    <div class="circle8"></div> 
 
    <div class="circle9"></div> 
 
</div>

1

応答性の高いサークルを取得する最もよい方法は、パーセンテージディメンションを使用することです。
必要に応じて、ビューポート(vh、vw)を使用することもできます。

パディングをパーセントで追加すると、幅に基づいて、幅を33%に、パディングトップ(またはボトム)を同じ値に設定すると、水平サイズと垂直サイズが同じになります。

jsFiddle link

.container { 
 
    width: 50vw; 
 
    margin: auto; 
 
} 
 

 
.container > div { 
 
    border-radius: 50%; 
 
    float: left; 
 
    width: 33.333%; 
 
    padding-top: 33.333%; 
 
} 
 

 
.circle1 {background-color: black;} 
 
.circle2 {background-color: darkred;} 
 
.circle3 {background-color: gold;} 
 
.circle4 {background-color: greenyellow;} 
 
.circle5 {background-color: blueviolet;} 
 
.circle6 {background-color: deeppink;} 
 
.circle7 {background-color: blue;} 
 
.circle8 {background-color: aqua;} 
 
.circle9 {background-color: darkorange;}
<div class="container"> 
 
    <div class="circle1"></div> 
 
    <div class="circle2"></div> 
 
    <div class="circle3"></div> 
 
    <div class="circle4"></div> 
 
    <div class="circle5"></div> 
 
    <div class="circle6"></div> 
 
    <div class="circle7"></div> 
 
    <div class="circle8"></div> 
 
    <div class="circle9"></div> 
 
</div>

関連する問題