Age*_*t69 2 html javascript css jquery
我试图将5个div放在一个圆形div周围,我该怎样才能实现呢?
到目前为止这是我的代码:
.main{
border: 2px dotted #000000;
border-radius: 50%;
width: 500px;
height: 500px;
}
.cirlce1{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50px;
}
.cirlce2{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50px;
}Run Code Online (Sandbox Code Playgroud)
<div class="main">
<div class="cirlce1"></div>
<div class="cirlce2"></div>
</div>Run Code Online (Sandbox Code Playgroud)
我希望我的输出像
谢谢.
您可以设置小圆圈的位置position: absolute;,然后一起玩top,left,right或bottom放置到所期望的地方.
我建议您使用它%来设置位置以便它具有响应性,但是如果大圆圈尺寸是静态的,您可以设置位置px.
.main{
border: 2px dotted #000000;
border-radius: 50%;
width: 500px;
height: 500px;
}
.cirlce1{
position: absolute;
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50%;
}
.cirlce2{
position: absolute;
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
left: 50%;
}Run Code Online (Sandbox Code Playgroud)
<div class="main">
<div class="cirlce1"></div>
<div class="cirlce2"></div>
</div>Run Code Online (Sandbox Code Playgroud)
关键是相对于大圈绝对定位小圈。
然后,您可以使用将它们居中calc()。
最终,将一系列变换应用于每个小圆,将其移到外侧边缘,然后将每个大圆绕360度(72度)旋转1/5。如果您使用的是预处理器(例如SASS),则可以使用循环来完成最后一步。
.main {
position: relative;
border: 2px dotted #000000;
border-radius: 50%;
width: 500px;
height: 500px;
}
.circle {
position: absolute;
left: calc(50% - 25px);
top: calc(50% - 25px);
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
}
.circle:nth-child(1) {
transform: translateX(250px);
}
.circle:nth-child(2) {
transform: rotate(72deg) translateX(250px);
}
.circle:nth-child(3) {
transform: rotate(144deg) translateX(250px);
}
.circle:nth-child(4) {
transform: rotate(216deg) translateX(250px);
}
.circle:nth-child(5) {
transform: rotate(288deg) translateX(250px);
}Run Code Online (Sandbox Code Playgroud)
<div class="main">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>Run Code Online (Sandbox Code Playgroud)