我正在尝试在 CSS 中使用
display:flex;
制作一行具有相同文本间距的元素。
这就是我得到的,我使用
display: inline-block;
和文本之间的间距差异来实现它 - 我希望对每个文本都进行相同的处理。
element {
border-width: 1px;
border-style: solid;
color: rgb(0, 146, 247);
display: inline-block;
height: 18px;
border-radius: 30px;
vertical-align: middle;
}
.footertext {
font-family: 'Open Sans', sans-serif;
color: rgb(124, 134, 205);
margin-left: 20px;
margin-right: 20px;
display: inline-block;
vertical-align: middle;
}
<div>
<p class="footertext">
First Line
</p>
<element></element>
<p class="footertext">
ABC
</p>
<element></element>
<p class="footertext">
Third Line
</p>
<element></element>
<p class="footertext">
DEFG
</p>
</div>
我需要文本之间那些有趣的元素,当我尝试使用
display:flex;
时,这些元素就会超出范围。
flex怎么样,除了第一个元素之外的所有元素都有左边框:
div {
display: flex;
}
.footertext {
padding-left: 20px;
padding-right: 20px;
}
.footertext + .footertext {
border-left: 3px solid rgb(0, 146, 247);
}
* { box-sizing: border-box; }
/* non-essential decorative styles */
.footertext {
font-family: 'Open Sans', sans-serif;
color: rgb(124, 134, 205);
}
<div>
<p class="footertext">First Line</p>
<p class="footertext">ABC</p>
<p class="footertext">Third Line</p>
<p class="footertext">DEFG</p>
</div>
这是一种简化的方法。
.footer-texts {
display: flex;
color:rgb(124,134,205);
font-family: sans-serif;
}
.footer-texts > span {
position: relative;
padding: .5rem 1rem;
display: flex;
text-align: center;
justify-content: center;
align-items: center;
flex: 0 1 25%;
}
.footer-texts > span:not(:last-child)::after {
content: '';
position: absolute;
right: -2px;
top: 25%;
width: 2px;
height: 50%;
background-color:rgb(0, 146,247);
}
<div class="footer-texts">
<span>First Line</span>
<span>ABC</span>
<span>Third Line<br />two lines</span>
<span>DEFG</span>
</div>
一些注意事项:
.someClassName > span
设置样式(其中 someClassName
是类名,span
是子级选择器。border-right
也是一个不错的候选者。有一篇关于该主题的好文章 https://ishadeed.com/article/flexbox-separator/