Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the grid classes ( col-sm-# and col-lg-# ) in Bootstrap 3

I'm getting started on Bootstrap 3 and I'm having some trouble understanding how the grid classes are meant to be used.

Here's what I've figured out so far:

It appears that the classes col-sm-# and col-lg-# differ from plain old col-# in that they will only apply when screens are above a certain size (768px and 992px respectively). If you omit the -sm- or -lg- the divs will never collapse into one column.

However, when I create two divs inside a row that are both col-sm-6 it seems they are only side by side when the window is between 768px and 992px wide. In other words, if I shrink the window all the way down and then slowly widen it, the layout is single column, then two columns, then back to single column again.

  1. Is this the intended behavior?
  2. If I want two columns for anything over 768px, should I apply both classes? (<div class="col-sm-6 col-lg-6">)
  3. Should col-6 also be included? <div class="col-6 col-sm-6 col-lg-6">
like image 486
emersonthis Avatar asked Aug 09 '13 12:08

emersonthis


People also ask

What is SM in grid?

Grid Classes The Bootstrap grid system has four classes: xs (for phones - screens less than 768px wide) sm (for tablets - screens equal to or greater than 768px wide) md (for small laptops - screens equal to or greater than 992px wide) lg (for laptops and desktops - screens equal to or greater than 1200px wide)

What does Col MD 5 class means?

In short, they are used to define at which screen size that class should apply: xs = extra small screens (mobile phones) sm = small screens (tablets) md = medium screens (some desktops) lg = large screens (remaining desktops)

What does Col SM 4 mean?

Three Equal Columns .col-sm-4. .col-sm-4. .col-sm-4. The following example shows how to get a three equal-width columns starting at tablets and scaling to large desktops.

How does Col SM work?

By skipping the number for column containers inside a row container (only typing col-sm ), you can create auto layouts. If you do this, it will automatically be determined how many columns each column element should span. All of them will have the same width and together occupy the whole available width.


2 Answers

[UPDATE BELOW]

I took another look at the docs and it appears I overlooked a section which talks specifically about this.

The answers to my questions:

  1. Yes, they are meant to apply only to specific ranges, rather than everything above a certain width.

  2. Yes, the classes are meant to be combined.

  3. It appears that this is appropriate in certain cases but not others because the col-# classes are basically equivalent to col-xsm-# or, widths above 0px (all widths).

Other than reading the docs too quickly, I think I was confused because I came into Bootstrap 3 with a "Bootstrap 2 mentality". Specifically, I was using the (optional) responsive styles (bootstrap-responsive.css) in v2 and v3 is quite different (for the better IMO).

UPDATE for stable release:

This question was originally written when RC1 was out. They made some major changes in RC2 so for anyone reading this now, not everything mentioned above still applies.

As of when I'm currently writing this, the col-*-# classes DO seem to apply upwards. So for example, if you want an element to be 12 columns (full width) for phones, but two 6 columns (half page) for tablets and up, you would do something like this:

<div class="col-xs-12 col-sm-6"> ... //NO NEED FOR col-md-6 or col-lg-6 

(They also added an additional xs break point after this question was written.)

like image 139
emersonthis Avatar answered Oct 13 '22 04:10

emersonthis


Here you have a very good tutorial, that explains, how to use the new grid classes in Bootstrap 3.

It also covers mixins etc.

like image 24
Srikanth Avatar answered Oct 13 '22 06:10

Srikanth