Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use Bootstrap's .w-100 class to split a row's columns into two rows, when you could just make two rows?

Tags:

On this page in the Bootstrap documentation at https://v4-alpha.getbootstrap.com/layout/grid/#equal-width-multi-row they give this example:

<div class="row">   <div class="col">col</div>   <div class="col">col</div>   <div class="w-100"></div>   <div class="col">col</div>   <div class="col">col</div> </div> 

This creates two rows with two equal-sized columns in each row. However, you can achieve this just by creating two rows:

<div class="row">   <div class="col">col</div>   <div class="col">col</div> </div> <div class="row">   <div class="col">col</div>   <div class="col">col</div> </div> 

Is there any difference between using the .w-100 CSS class and just creating two rows instead?

like image 662
Al Sweigart Avatar asked Apr 14 '17 04:04

Al Sweigart


People also ask

What is the use of W 100 in Bootstrap?

w-100 class to split a row's columns into two rows, when you could just make two rows?

How do I split a column into two rows in Bootstrap?

The column of a list can be split into rows using the grid system of BootStrap. The 'row' and 'col' classes of BootStrap enables splitting any area into rows and columns.

What is the use of row class in Bootstrap?

In Bootstrap, the "row" class is used mainly to hold columns in it. Bootstrap divides each row into a grid of 12 virtual columns. In the following example, the col-md-6 div will have the width of 6/12 of the "row"s div, meaning 50%.

Which layout is 100 Width in Bootstrap?

Containers. Containers are the most basic layout element in Bootstrap and are required when using our default grid system. Choose from a responsive, fixed-width container (meaning its max-width changes at each breakpoint) or fluid-width (meaning it's 100% wide all the time).


1 Answers

In this specific case, there is no difference.

However, keeping the cols in a single .row is generally better for these reasons...

Column ordering

Suppose you instead want to switch the order of the first and last columns on md and up. This would not be possible with separate .row containers. Keeping all the col in a single .row makes it possible.

<div class="row">     <div class="col flex-md-last">col 1</div>     <div class="col">col 2</div>     <div class="w-100"></div>     <div class="col">col 3</div>     <div class="col flex-md-first">col 4</div> </div> 

Responsive layouts

Another example. Suppose you instead wanted a layout of:

  • 4 cols across 1 row on md width (4x1)
  • 2 cols across 2 rows on xs width (2x2)

Again, this would not be possible with separate .row divs. But, since the w-100 can be used responsively, this is possible by keeping all the cols in a single row.

<div class="row">     <div class="col col-md-3">col 1</div>     <div class="col col-md-3">col 2</div>     <div class="w-100 hidden-md-up"></div>     <div class="col col-md-3">col 3</div>     <div class="col col-md-3">col 4</div> </div> 

Demo of the layouts

like image 75
Zim Avatar answered Sep 23 '22 00:09

Zim