What is the difference among col-lg-*
, col-md-*
and col-sm-*
in Twitter Bootstrap?
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- How to add a “active” class to a carousel first el
- Add animation to jQuery function Interval
- jQuery hover to slide?
From Twitter Bootstrap documentation:
.col-sm-*
,.col-md-*
,.col-lg-*
.One particular case : Before learning bootstrap grid system, make sure browser zoom is set to 100% (a hundred percent). For example : If screen resolution is (1600px x 900px) and browser zoom is 175%, then "bootstrap-ped" elements will be stacked.
HTML
Chrome zoom 100%
Browser 100 percent - elements placed horizontally
Chrome zoom 175%
Browser 175 percent - stacked elements
TL;DR
.col-X-Y
means on screen size X and up, stretch this element to fill Y columns.Bootstrap provides a grid of 12 columns per
.row
, so Y=3 means width=25%.xs, sm, md, lg
are the sizes for smartphone, tablet, laptop, desktop respectively.The point of specifying different widths on different screen sizes is to let you make things larger on smaller screens.
Example
Meaning: 50% width on Desktops, 100% width on Mobile, Tablet, and Laptop.
well it's used to tell bootstrap how many columns are to be placed in a row depending on the screen size-
would show only 2 columns in a row in extra small(xs) screen, in the same way as sm defines a small screen, md(medium sized), lg(large sized), but according to bootstrap smaller first rule, if you mention
then 2 columns would be shown in every row for screen sizes from xs upto sm(included) and changes when it gets next size i.e. for md up to lg(included) for a better understanding of screen sizes try running them in various screen modes in chrome's developer mode(ctr+shift+i) and try various pixels or devices
Updated 2018...
The Bootstrap 3 grid comes in 4 tiers (or "breakpoints")...
.col-xs-*
).col-sm-*
).col-md-*
).col-lg-*
).These grid sizes enable you to control grid behavior on different widths. The different tiers are controlled by CSS media queries.
So in Bootstrap's 12-column grid...
col-sm-3
is 3 of 12 columns wide (25%) on a typical small device width (> 768 pixels)col-md-3
is 3 of 12 columns wide (25%) on a typical medium device width (> 992 pixels)The smaller tier (
xs
,sm
ormd
) also defines the size for larger screen widths. So, for the same size column on all tiers, just set the width for the smallest viewport...<div class="col-lg-3 col-md-3 col-sm-3">..</div>
is the same as,<div class="col-sm-3">..</div>
Larger tiers are implied. Because
col-sm-3
means3 units on sm-and-up
, unless specifically overridden by a larger tier that uses a different size.xs
(default) > overridden bysm
> overridden bymd
> overridden bylg
Combine the classes to use change column widths on different grid sizes. This creates a responsive layout.
<div class="col-md-3 col-sm-6">..</div>
The
sm
,md
andlg
grids will all "stack" vertically on screens/viewports less than 768 pixels. This is where thexs
grid fits in. Columns that use thecol-xs-*
classes will not stack vertically, and continue to scale down on the smallest screens.Resize your browser using this demo and you'll see the grid scaling effects.
In Bootstrap 4 there is a new
-xl-
size, see this demo. Also the-xs-
infix has been removed, so smallest columns are simplycol-1
,col-2
..col-12
, etc..col-*
- 0 (xs)col-sm-*
- 576pxcol-md-*
- 768pxcol-lg-*
- 992pxcol-xl-*
- 1200pxBootstrap 4 Grid Demo
Also, this article explains more about the Bootstrap grid