30秒学会 CSS 片段 · 2020年3月26日

30秒学会 CSS 片段 – Evenly distributed children

Evenly distributes child elements within a parent element.

  • display: flex enables flexbox.
  • justify-content: space-between evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.
  • Alternatively, use justify-content: space-around to distribute the children with space around them, rather than between them.

预览

Item1

Item2

Item3



HTML

<div class="evenly-distributed-children">
  <p>Item1</p>
  <p>Item2</p>
  <p>Item3</p>
</div>

CSS

.evenly-distributed-children {
  display: flex;
  justify-content: space-between;
}

翻译自:https://www.30secondsofcode.org/css/s/evenly-distributed-children