Home >Web Front-end >CSS Tutorial >How to Align the Last Row in a Flexbox Grid with `justify-content: space-between`?
Flex-box: How to Align Last Row to Grid
In a flex-box layout with a container like:
.grid { display: flex; flex-flow: row wrap; justify-content: space-between; }
The goal is to align items in the last row to be level with others. Using justify-content: space-between; remains crucial due to adjustable grid width and height.
Currently, with:
.grid { display: flex; flex-flow: row wrap; justify-content: space-between; } .item { width: 100px; height: 66px; background-color: rgba(255, 255, 255, 0.2); border: 1px solid rgba(0, 0, 0, 0.4); border-radius: 5px; box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); margin-bottom: 10px; }
The item in the bottom right appears out of alignment.
To fix this:
.grid { display: flex; flex-flow: row wrap; justify-content: space-between; } .grid::after { content: ""; flex: auto; }
A ::after is added to autofill the space, eliminating the need for HTML adjustments.
The above is the detailed content of How to Align the Last Row in a Flexbox Grid with `justify-content: space-between`?. For more information, please follow other related articles on the PHP Chinese website!