Problem:
Attempting to display multiple rows of square elements (3 per row) with equal height, but they all appear on the same line.
Initial Considerations:
The default setting for a flex container is flex-wrap: nowrap, which restricts flex items to a single line. To enable wrapping, this property must be set to wrap.
Solution:
Add flex-wrap: wrap to the parent container style:
#list-wrapper { display: flex; flex-wrap: wrap; width: 100%; }
Ensure that the flex items' dimensions are defined (e.g., width and height) to allow the browser to calculate the appropriate layout:
#list-wrapper div { width: 33.33%; } #list-wrapper div img { flex: 1; }
Additional Notes:
The above is the detailed content of Why Aren't My Flex Items Wrapping to Multiple Rows?. For more information, please follow other related articles on the PHP Chinese website!