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?
w-100 class to split a row's columns into two rows, when you could just make two rows?
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.
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%.
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).
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:
md
width (4x1)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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With