Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to add col-md selector in Bootstrap 3?

I tried searching for an answer to this to no avail. Basically what I'm wondering is if it is necessary to specify a col-md-* value in Bootstrap 3, or if you can just use, say, col-xs-12 and col-sm-* and have the col-sm-* value dictate the col size all the way to some massive display.

This seems like a no-brainer (that having col-sm would be fine) but the documentation includes seemingly redundant col-md-* values as well, such as here (taken from "Example: Mobile, Tablet, and Desktop" under "Grid System" in CSS section:

<div class="row">
  <div class="col-xs-6 col-sm-4 col-md-4">.col-xs-6 .col-sm-4 .col-md-4</div>
  <div class="col-xs-6 col-sm-4 col-md-4">.col-xs-6 .col-sm-4 .col-md-4</div>
  <!-- Optional: clear the XS cols if their content doesn't match in height -->
  <div class="clearfix visible-xs"></div>
  <div class="col-xs-6 col-sm-4 col-md-4">.col-xs-6 .col-sm-4 .col-md-4</div>
</div>

Any clarification here would be greatly appreciated. Thanks!

like image 297
Jeff W Avatar asked Aug 16 '13 22:08

Jeff W


People also ask

What is the purpose of using Col-Md class in Bootstrap?

col-md: It is used for medium screen size devices (screen width greater than or equal to 768px). . col-lg: It is used for large screen size devices (screen width greater than or equal to 992px).

What is Col-Md offset 3?

offset-md-3 which will offset the desired column element with 3 columns to the right from its default position on medium screen sizes and above. . offset classes always shifts its content to the right. This all stuff produced results .

Why is Col-Md used?

col-md-4: This class is used when the device size is medium or greater than 768px and the maximum width of container is 720px and you want the width equal to 4 columns.

Does Bootstrap 3 support flexbox?

Bootstrap 3 used floats to handle the layout in place of the flexbox, however, Bootstrap 4 uses flexbox to handle the layout. The flexbox layout makes it easier to design a flexible responsive layout structure without using float or positioning.


Video Answer


1 Answers

Your intuition is correct, the lowest value you set (xs, sm or md) will dictate for the larger screen sizes; that means if you want your div to span 4 columns starting at small devices and all the way up, you just have to set .col-sm-4.

It works this way because of how the media queries are set up:

/* Extra small devices (phones, up to 480px) */ 
/* No media query since this is the default in Bootstrap */

/* Small devices (tablets, 768px and up) */ 
@media (min-width: @screen-tablet) { ... }

/* Medium devices (desktops, 992px and up) */ 
@media (min-width: @screen-desktop) { ... }

/* Large devices (large desktops, 1200px and up) */ 
@media (min-width: @screen-large-desktop) { ... }

If not overridden, classes for small devices will apply to larger screens as well

like image 168
omma2289 Avatar answered Sep 20 '22 20:09

omma2289