Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 grid, does it *really* matter how many columns are in a row?

Tags:

I have a form layout that has bootstrap 3 form groups on it. I want these form groups in a single column on < small, 2 columns on tablet size break and 4 column on larger screens.

I have it apparently working perfectly, however after doing some reading here what I did seems to violate the supposed rule that every column in a row must add up to 12. However every tutorial and docs I could find always use weasel words like "should" or "ideally" when saying it should add up to 12. There doesn't seem to be a clear guidance here.

I defined my groups like this:

<div class="row">     <div class="form-group col-md-6 col-lg-3" ><!--....etc--> 

and I currently have 4 of these in each row. This means that the 4 * col-lg-3 adds up to 12 but the 4 * col-md-6 form group divs adds up to 24 not 12.

However this doesn't seem to matter and it works perfectly at each breakpoint.

Should I be concerned? Does it matter in any way? Surely I'm not supposed to do two completely different layouts that duplicate all these controls once each for col-md-6 and col-lg-3 on the same page?

like image 656
JohnC Avatar asked May 06 '14 18:05

JohnC


People also ask

How many columns are in a row in Bootstrap grid system?

Columns are incredibly flexible. There are 12 template columns available per row, allowing you to create different combinations of elements that span any number of columns.

Do Bootstrap columns need to be in a row?

Yes, you need to use row. The row > col relationship is the same in both Bootstrap 3 and 4 in that..

Is Bootstrap always 12 columns?

Bootstrap uses a 12-column grid system that can update itself responsively based on screen size. There are only 38 highly composite numbers below the one million threshold, including 120, 2520, 5040, 55440 and 720720.

Why does Bootstrap use 12 columns?

Well, a 12-column layout was how Bootstrap developed their layout technique. It is more effective because the layout was only intended to grow as large as the body of the page and shrink as small as a few words.


1 Answers

No, there's nothing to mandate that the bootstrap grid must add up to 12 columns.
It's just a preference / stylistic thing.

Less than 12 Columns -> Aligns Left:

If you have less than twelve of the columns filled, by default they will left align, leaving empty space to the right.

The following code:

<div class='row'>     <div class="col-xs-2">Hi</div>     <div class="col-xs-2">Hi</div> </div> 
.row > div {     background: lightgrey;     border: 1px solid grey; } 

Results in this: (Demo in Fiddle)

screenshot

More than 12 Columns -> Wraps:

If the total adds to more than 12 columns, as long as the columns are within a row class, they will just wrap to additional rows. A good use case would be a photo grid system where you would like to add tons of photos but don't know how many rows you'll have and would still like to define the number of columns.

The following code:

<div class='row'>     <div class="col-xs-6">Hi</div>     <div class="col-xs-6">Hi</div>     <div class="col-xs-6">Hi</div>     <div class="col-xs-6">Hi</div> </div> 

Results in this: (Demo in Fiddle)

screenshot2

Other than that, sometimes it's the case that 12 column layouts look better, but you don't have to use them; it's not a sudoku :)

like image 93
KyleMit Avatar answered Nov 02 '22 06:11

KyleMit