Managing Flexbox Item Spacing
Question:
In flexbox layouts, how can I adjust the distance between items without resorting to intricate margins?
**Answer:
CSS Gap Property:
For advanced browsers, the gap property can be utilized to establish spacing both vertically and horizontally in flexbox, grid, and multi-column layouts.
#box { display: flex; gap: 10px; }
CSS Row-Gap Property:
For vertical spacing specifically in flexbox and grid layouts, the row-gap property is an option.
#box { display: flex; row-gap: 10px; }
CSS Column-Gap Property:
In multi-column, flexbox, and grid layouts, the column-gap property controls horizontal spacing.
#box { display: flex; column-gap: 10px; }
Example:
The following snippet demonstrates the use of the gap property to create spacing between flexbox items:
<div>
#box { display: flex; flex-wrap: wrap; width: 200px; background-color: red; gap: 10px; } .item { background: gray; width: 50px; height: 50px; border: 1px black solid; }
The above is the detailed content of How Can I Easily Control Spacing Between Flexbox Items?. For more information, please follow other related articles on the PHP Chinese website!