To force the next flex item to go to a new line in a CSS flex container, you can use the break-after property.
Values for break-after
- auto: This is the default value. It allows the browser to handle breaks according to its default behavior.
- always: Forces a break after the element. In a multi-column layout, this will ensure that the next content starts in a new column. In print styles, this will start a new page.
- avoid: Prevents a break from occurring after the element if possible. The content will try to remain on the same page or column.
- left: In print layouts, this forces a page break before the element starts, ensuring that the element will start on a new odd-numbered (right) page if the content was already on a left page.
- right: In print layouts, this forces a page break before the element starts, ensuring that the element will start on a new even-numbered (left) page if the content was already on a right page.
- column: Forces a column break after the element in a multi-column layout, ensuring the next content starts in a new column.
- none: This is similar to auto and allows the default behavior without forcing or avoiding any breaks.
Source code viewer
<style> .container { display: flex; flex-wrap: wrap; } .item { flex: 1; } .new-line { break-after: column; /* Forces a break after this item */ } </style> <div class="container"> </div>Programming Language: HTML