我希望代码显示 3 个条,而 3 个点最终成为下拉选项。出于某种原因,3 个点中的第一个点的间距不正确。
#dropdown {
background: #3f51b5;
padding: 30px;
margin: 0px;
}
#dot {
width: 5px;
height: 5px;
background: white;
border-radius: 50%;
float: right;
}
#bar {
width: 25px;
height: 3px;
background: white;
margin: 5px;
}
<div id="dropdown">
<div id="dot"></div>
<div id="bar"></div>
<div id="dot"></div>
<div id="bar"></div>
<div id="dot"></div>
<div id="bar"></div>
</div>
返回的图片:
最佳答案
这对 float 来说很难。 一个可能的解决方案是将点和条包裹在一个 div 中。 之后,您可以将那些包装 div 放置在您喜欢的样式中。 我在以下代码片段中为此使用了 flexbox。
#dropdown {
display: flex;
justify-content: space-between;
align-items: center;
background: #3f51b5;
padding: 30px;
margin: 0px;
}
.dot {
width: 5px;
height: 5px;
margin: 5px;
background: white;
border-radius: 50%;
}
.bar {
width: 25px;
height: 3px;
background: white;
margin: 5px;
}
<div id="dropdown">
<div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
<div>
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</div>
p.s.:对于重复元素,您应该使用关键字 class
而不是 id
。这可能仍然有效,但被认为是不好的做法,并且可能会破坏使用该 id
的 javascript 实现。
关于html - 如何将三个点均匀地间隔为瘦汉堡菜单图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54148184/