gpt4 book ai didi

html - 在网页中创建响应圈

转载 作者:太空宇宙 更新时间:2023-11-04 01:57:27 25 4
gpt4 key购买 nike

我想创建一个由 9 个圆圈组成的响应式页面。在下面的代码圈中,只要我更改浏览器大小(无响应),就会更改它们的位置。我尝试使用 CSS @media 查询,但无法创建响应。

我应该使用 % 作为位置宽度、高度而不是固定的 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>

最佳答案

代码如下:

.full{ margin:0 auto; width:70%;}
.circle1{
width: 15%;
padding-top: 15%;
margin:0 42%;
background-color: black;
border-radius: 50%;
display:inline-block;
}
.circle2{
width: 15%;
padding-top: 15%;
margin-left: 20%;
background-color:darkred;
border-radius: 50%;
display:inline-block;
margin-top:20px;
}
.circle3{
width: 15%;
padding-top: 15%;
margin-left: 26%;
background-color:gold;
border-radius: 50%;
display:inline-block;
margin-top:20px;
margin-right: 15%;
}
.circle4{
width: 15%;
padding-top: 15%;
margin-left: 0%;
background-color:greenyellow;
border-radius: 50%;
display:inline-block;
margin-top:20px;
}
.circle5{
width: 15%;
padding-top: 15%;
margin-left: 26%;
background-color:blueviolet;
border-radius: 50%;
display:inline-block;
margin-top:20px;
}
.circle6{
width: 15%;
padding-top: 15%;
margin-left: 26%;
background-color:deeppink;
border-radius: 50%;
display:inline-block;
margin-top:20px;
}
.circle7{
width: 15%;
padding-top: 15%;
margin-left: 20%;
background-color:blue;
border-radius: 50%;
display:inline-block;
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) {
.full{width:100%;}
}
<div class="full">
<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>

关于html - 在网页中创建响应圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42335163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com