6 September 2024

To set a flex container with flex-direction: row and ensure it takes up 100% width, you can do it like in this snippet. With flex-direction: row, the flex items (the children) will be aligned in a row. Adding flex: 1 to the children ensures that they grow and take equal space within the row.

Source code viewer
  1. .row {
  2. display: flex;
  3. flex-direction: row; /* Makes sure items are aligned horizontally */
  4. }
  5.  
  6. .child {
  7. flex: 1; /* Allows the children to take equal width */
  8. }
  9.  
  10. <div class="row">
  11. <div class="child">Child 1</div>
  12. <div class="child">Child 2</div>
  13. <div class="child">Child 3</div>
  14. </div>
  15.  
Programming Language: HTML