javascript - 圆形 Div 周围的 Div

标签 javascript jquery html css

我想在一个圆形 div 周围放置 5 个 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;
}
<div class="main">
	<div class="cirlce1"></div>
	<div class="cirlce2"></div>
</div>

我希望我的输出是这样的

enter image description here

谢谢。

最佳答案

关键是让小圆圈相对于大圆圈绝对定位。

然后您可以使用 calc() 将它们居中。

最后,对每个小圆应用一系列变换,将它们移动到外边缘,然后将每个小圆围绕大圆旋转 360 度的 1/5(72 度)。如果您使用的是 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);
}
<div class="main">
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
</div>

关于javascript - 圆形 Div 周围的 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46157122/

相关文章:

javascript - 通过抓取其背景来拖动 div 内容

javascript - 使用javascript进行最小最大验证

javascript - 动态向div添加新的jqPlot图表使旧的图表变空

javascript - 使输入框从左或右滑入

html - PSD 切片良好实践

Javascript:为什么我们的网站在终端服务 session 中速度极慢?

javascript - REGEX 帮助,= 符号后的变量名称

javascript - 发现哪个表单按钮触发了提交

jquery - TypeIt JQuery 插件 : Remove cursor when typing has completed

html - 子 div 未将自身与父 div 内的另一个 div 对齐