Home > Web Front-end > CSS Tutorial > How to Make a Flex Item Span the Entire Row Below Other Flex Items?

How to Make a Flex Item Span the Entire Row Below Other Flex Items?

Susan Sarandon
Release: 2024-12-11 03:32:10
Original
400 people have browsed it

How to Make a Flex Item Span the Entire Row Below Other Flex Items?

Force Full-Width Flex Item to Span Entire Row

Problem:

In a flex layout, the aim is to retain the first two child elements on a single row, while the third element occupies its own full-width row below. The challenge arises from the desire to utilize flex-grow and flex-shrink properties for the first two elements, while ensuring that the third element stretches to the full width of the parent container and appears below the first two.

Solution:

To force the third element to span 100% width and appear on a new row below the other two:

  • Set flex-basis: 100% on the third element. This ensures it takes up all available space in its row and is pushed to a new line.
  • Implement flex-wrap: wrap on the parent container. This allows flex items to wrap onto multiple rows, accommodating items that cannot fit within the current row's width.

Example Code:

.parent {
  display: flex;
  flex-wrap: wrap;
}

#range, #text {
  flex: 1;
}

.error {
  flex: 0 0 100%; /* flex-grow, flex-shrink, flex-basis */
  border: 1px dashed black;
}
Copy after login
<div class="parent">
  <input type="range">
Copy after login

With this approach, the first two elements occupy the same row, sharing the available width, while the third element spans the full width of the parent container and is positioned on a new row below.

The above is the detailed content of How to Make a Flex Item Span the Entire Row Below Other Flex Items?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template