【发布时间】:2022-02-03 18:26:53
【问题描述】:
寻找一种在一组单词之间创建线条的方法。我可以让它发挥作用,但我并不总是知道单词的长度,而且我无法在文本和行之间保持均匀的间距。
我想我也许可以添加一些空的 div 来让它工作,但我试图避免将无用的标记添加到 DOM 中
.progress-bar {
display: flex;
width: 100%;
justify-content: space-between;
margin-top: 50px;
}
.progress-bar p {
display: block;
position: relative;
width: 100%;
text-align: center;
line-height: 0.1em;
}
.progress-bar p::after {
content: "";
z-index: -1;
position: absolute;
bottom: 0;
top: 0;
right: 0;
width: 25%;
height: 2px;
background: black;
}
.progress-bar p:last-of-type::after {
background: none;
content: "";
}
<div class="progress-bar">
<p>text one</p>
<p> text two</p>
<p>text three</p>
<p>text four</p>
</div>
【问题讨论】:
-
您的标题听起来好像您希望文本之间的间距均匀,但是您的代码在文本之间给出了不相等的间距(因为它们的长度不同并且您使用了 flex)。您能否确认您想要哪个,因为它显然会影响文本间行的绘制方式。