[html] Force flex item to span full row width

I'm trying to retain the first 2 child elements on the same row while the third element is in its own below at full width, all while using flex.

I'm particularly interested in using the flex-grow and flex-shrink properties on the first 2 elements (which is one of my reasons for not using percentages) however the third element really must be full width and below the first two.

The label element is added programmatically after the text element when there's an error and I can't change the code.

How do I force the label element to span a 100% width below the other two elements which are positioned using flex?

_x000D_
_x000D_
.parent {_x000D_
  display: flex;_x000D_
  align-items: center;_x000D_
  width: 100%;_x000D_
  background-color: #ececec;_x000D_
}_x000D_
_x000D_
.parent * {_x000D_
  width: 100%;_x000D_
}_x000D_
_x000D_
.parent #text {_x000D_
  min-width: 75px;_x000D_
  flex-shrink: 2.25;_x000D_
}
_x000D_
<div class="parent">_x000D_
  <input type="range" id="range">_x000D_
  <input type="text" id="text">_x000D_
  <label class="error">Error message</label>_x000D_
</div>
_x000D_
_x000D_
_x000D_

This question is related to html css flexbox

The answer is


When you want a flex item to occupy an entire row, set it to width: 100% or flex-basis: 100%, and enable wrap on the container.

The item now consumes all available space. Siblings are forced on to other rows.

_x000D_
_x000D_
.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;
}
_x000D_
<div class="parent">
  <input type="range" id="range">
  <input type="text" id="text">
  <label class="error">Error message (takes full width)</label>
</div>
_x000D_
_x000D_
_x000D_

More info: The initial value of the flex-wrap property is nowrap, which means that all items will line up in a row. MDN


Questions with html tag:

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment Angular 6: saving data to local storage Vue.js get selected option on @change Bootstrap 4 multiselect dropdown How to add bootstrap in angular 6 project? Angular 5 Button Submit On Enter Key Press Angular 5, HTML, boolean on checkbox is checked How to render string with html tags in Angular 4+? bootstrap 4 file input doesn't show the file name How can I execute a python script from an html button? Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width Failed to load resource: the server responded with a status of 404 (Not Found) css Change arrow colors in Bootstraps carousel Bootstrap 4 Dropdown Menu not working? CSS Grid Layout not working in IE11 even with prefixes How to prevent page from reloading after form submit - JQuery Centering in CSS Grid Detecting real time window size changes in Angular 4 Angular 4 img src is not found (change) vs (ngModelChange) in angular Bootstrap 4: Multilevel Dropdown Inside Navigation Align the form to the center in Bootstrap 4 How to style a clicked button in CSS How do I change the font color in an html table? Redirecting to a page after submitting form in HTML Load json from local file with http.get() in angular 2 display: flex not working on Internet Explorer Scroll to element on click in Angular 4 How to extract svg as file from web page force css grid container to fill full screen of device How does the "position: sticky;" property work? HTML5 Video autoplay on iPhone Disable button in angular with two conditions? CSS hide scroll bar, but have element scrollable CSS grid wrapping How to load image (and other assets) in Angular an project? Flask - Calling python function on button OnClick event How can I make Bootstrap 4 columns all the same height? Wrapping a react-router Link in an html button

Questions with css tag:

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width Font Awesome 5 font-family issue Failed to load resource: the server responded with a status of 404 (Not Found) css CSS class for pointer cursor How and where to use ::ng-deep? Styling mat-select in Angular Material What is the difference between CSS and SCSS? iPhone X / 8 / 8 Plus CSS media queries Change arrow colors in Bootstraps carousel Bootstrap 4 Dropdown Menu not working? Add class to an element in Angular 4 CSS Grid Layout not working in IE11 even with prefixes Search input with an icon Bootstrap 4 Bootstrap 4 - Inline List? Centering in CSS Grid Bootstrap 4, how to make a col have a height of 100%? Equal height rows in CSS Grid Layout Bootstrap 4: Multilevel Dropdown Inside Navigation Align the form to the center in Bootstrap 4 Customize Bootstrap checkboxes How to style a clicked button in CSS How can I get the height of an element using css only display: flex not working on Internet Explorer force css grid container to fill full screen of device How does the "position: sticky;" property work? bootstrap 4 row height Prevent content from expanding grid items Bootstrap 4 File Input CSS hide scroll bar, but have element scrollable CSS grid wrapping Bootstrap 4 Change Hamburger Toggler Color How can I make Bootstrap 4 columns all the same height? How to hide collapsible Bootstrap 4 navbar on click Bootstrap 4 Center Vertical and Horizontal Alignment Cannot read property 'style' of undefined -- Uncaught Type Error How to window.scrollTo() with a smooth effect Vertical Align Center in Bootstrap 4 How to implement a Navbar Dropdown Hover in Bootstrap v4? CSS change button style after click What is correct media query for IPad Pro? How do I specify row heights in CSS Grid layout?

Questions with flexbox tag:

Force flex item to span full row width vuetify center items into v-flex Equal height rows in CSS Grid Layout display: flex not working on Internet Explorer Center the content inside a column in Bootstrap 4 Vertical Align Center in Bootstrap 4 How to use zIndex in react-native Bootstrap 4 align navbar items to the right Does 'position: absolute' conflict with Flexbox? Make flex items take content width, not width of parent container Flexbox not working in Internet Explorer 11 Make div fill remaining space along the main axis in flexbox Why does flexbox stretch my image rather than retaining aspect ratio? ReactNative: how to center text? What does flex: 1 mean? React Native absolute positioning horizontal centre Specifing width of a flexbox flex item: width or basis? React native text going off my screen, refusing to wrap. What to do? Prevent flex items from overflowing a container Making a flex item float right Equal height rows in a flex container CSS align one item right with flexbox Text in a flex container doesn't wrap in IE11 react-native - Fit Image in containing View, not the whole screen size Position last flex item at the end of container Prevent flex items from stretching Chrome / Safari not filling 100% height of flex parent Shrink to fit content in flexbox, or flex-basis: content workaround? 100% width in React Native Flexbox How to make a flex item not fill the height of the flex container? In CSS Flexbox, why are there no "justify-items" and "justify-self" properties? Align an element to bottom with flexbox Maintain image aspect ratio when changing height Flexbox: how to get divs to fill up 100% of the container width without wrapping? How to set a fixed width column with CSS flexbox How to specify line breaks in a multi-line flexbox layout? Flexbox: 4 items per row How to make flexbox items the same size? How to stretch children to fill cross-axis? Set min-width either by content or 200px (whichever is greater) together with max-width How to align flexbox columns left and right? What's the difference between align-content and align-items? What's the difference between display:inline-flex and display:flex? CSS Flex Box Layout: full-width row and columns CSS flex, how to display one item on first line and two on the next line CSS flexbox vertically/horizontally center image WITHOUT explicitely defining parent height How to vertically align text inside a flexbox? Fill remaining vertical space with CSS using display:flex Flexbox not giving equal width to elements How do I make flex box work in safari?