In a flex-box container with flex-flow: row wrap; and justify-content: space-between;, the last row items may not be aligned correctly. This article explores a simple solution to align the last row with the other rows, maintaining the desired spacing.
The solution utilizes the ::after pseudo-element to autofill the remaining space in the container. By assigning flex: auto; to ::after, it fills the vacant space without any extra content in the HTML.
.grid {<br> display: flex;<br> flex-flow: row wrap;<br> justify-content: space-between;<br>}</p><p>.grid::after {<br> content: "";<br> flex: auto;<br>}<br>
This approach provides a clean and straightforward solution, avoiding the need to add unnecessary elements to the HTML code. Check out the live demo at http://codepen.io/DanAndreasson/pen/ZQXLXj to witness its effectiveness.
The above is the detailed content of How Can I Ensure Even Spacing in the Last Row of a Flexbox Grid with `justify-content: space-between`?. For more information, please follow other related articles on the PHP Chinese website!