flexbox中元素之间的行分隔符

How*_*oGo 7 css flexbox

我正在尝试display:flex;在 CSS 中使用相同的文本间距制作一行元素。

这是我得到的,我使用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;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

我需要文本之间的那些有趣元素,当我尝试使用display:flex;这些元素时,这些元素就会越界。

Mic*_*l_B 10

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);
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <p class="footertext">First Line</p>
  <p class="footertext">ABC</p>
  <p class="footertext">Third Line</p>
  <p class="footertext">DEFG</p>
</div>
Run Code Online (Sandbox Code Playgroud)


And*_*hiu 8

这是一种简化的方法。

.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);
}
Run Code Online (Sandbox Code Playgroud)
<div class="footer-texts">
  <span>First Line</span>
  <span>ABC</span>
  <span>Third Line<br />two lines</span>
  <span>DEFG</span>
</div>
Run Code Online (Sandbox Code Playgroud)

一些注意事项:

  • 而不是向所有子项添加相同的类,只需向父项和样式添加一个 using .someClassName > span(where someClassNameis the class name and spanis the child selector.
  • 尽可能使用伪元素而不是 DOM 元素来向标记添加分隔符或任何其他类型的装饰器。在这种特殊情况下border-right,也是一个很好的候选人。