Short version: is col-x-offset-n applied only to the left, or does it apply to left and right if this is what it needs to make 12? For instance can I just do "col-x-10 col-x-offset-1" to get a 10 column container with 1 extra column on both left and right? It seems to work but this isn't what the documentation suggests should happen.
Longer version: As an example, I'm trying to center a div using bootstrap 3 grid system. At col-xs size I want it to be full width, but above that I want it centered with a little more padding on each side. All docs of course say that the number of columns should total 12. So if I do:
<div class="container">
<div class="row">
<div class="col-sm-1">
</div>
<div class="col-sm-10">
...content here...
</div>
<div class="col-sm-1">
</div>
</div>
</div>
it works as I expect with the two empty col-sm-1 columns acting like padding on the left and right. But I can do it with less markup using -offset:
<div class="container">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
...content here...
</div>
<div class="col-sm-1">
</div>
</div>
</div>
As the bootstrap docs say: "Move columns to the right using .col-md-offset-* classes. These classes increase the left margin of a column by * columns." So in this case I have 10 columns, plus 1 column in the offset, plus 1 column in the following empty col-sm-1 div, equals 12 columns.
Now for the question finally: if I remove the final empty col-sm-1 div I still get the same result (page is centered as with both examples before), but my columns now only add up to 11.
<div class="container">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
...content here...
</div>
</div>
</div>
Is this okay to do? Is Bootstrap just filling in the last column for me? I would like to just drop it and use only "col-sm-10 col-sm-offset-1" or "col-sm-8 col-sm-offset-2" or "col-sm-6 col-sm-offset-3" (even though these only add up to 11,10,and 9 total columns respectively), but is this really the way to do it or is it just a quirk that it works out okay? It almost seems like bootstrap applies the offset to both left and right if it needs to, but I can't find any documentation to confirm that.
(And maybe with this simple example there is an easier way to do what I describe here, but I'm trying to understand how -offset works, not to just center a simple div with margin: 0 auto; or something like that.)
Yes, it's ok to have more that 12 columns in a row It will just make the extra columns wrap to the next line. So, with your example you'd have 2 rows of 4. From the Bootstrap docs (http://getbootstrap.com/css/#grid)..
If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.
Bootstrap's grid system allows up to 12 columns across the page.
Bootstrap was made for a 12-col usage.@grid-columns : Number of columns in the grid. @grid-gutter-width Padding between columns. Gets divided in half for the left and right.
In the bootstrap documentation they provide examples which do not add up to 12.
This should be acceptable:
<div class="container">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
...content here...
</div>
</div>
</div>
For reference http://getbootstrap.com/css/#grid go to the "offsetting columns" chapter and the last example adds up to 9, and is a similar center example.
<div class="row">
<div class="col-md-6 col-md-offset-3">.col-md-6 .col-md-offset-3</div>
</div>
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