[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


Examples related to html

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

Examples related to css

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

Examples related to flexbox

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