Bootstrap 3 Training at Ma'an (OG Foundation)
to the new members in IT Department
Made By Me
Size: 194.41 KB
Language: en
Added: Jun 26, 2015
Slides: 8 pages
Slide Content
Bootstrap Grid System
Bootstrap's grid system allows up to 12 columns across the page.
If you do not want to use all 12 column individually, you can group the
columns together to create wider columns:
span
1
span
1
span
1
span
1
span
1
span
1
span
1
span
1
span
1
span
1
span
1
span
1
span 4 span 4 span 4
span 4 span 8
span 6 span 6
span 12
Bootstrap' grid system is responsive, and the columns will re-arrange
depending on the screen size: On a big screen it might look better with the
content organized in three columns, but on a small screen it would be better
if the content items where stacked on top of each other.
Tip: Remember that grid columns should add up to twelve for a row. More
than that, columns will stack no matter the viewport.
Grid Classes
The Bootstrap grid system has four classes:
xs (for phones)
sm (for tablets)
md (for desktops)
lg (for larger desktops)
The classes above can be combined to create more dynamic and flexible
layouts.
Tip: Each class scales up, so if you wish to set the same widths for xs and
sm, you only need to specify xs.
Grid System Rules
Some Bootstrap grid system rules:
Rows must be placed within a .container (fixed-width) or .container-
fluid (full-width) for proper alignment and padding
Use rows to create horizontal groups of columns
Content should be placed within columns, and only columns m ay be
immediate children of rows
Predefined classes like .row and .col-sm-4 are available for quickly
making grid layouts
Columns create gutters (gaps between column content) via padding.
That padding is offset in rows for the first and last column via negative
margin on .rows
Grid columns are created by specifying the number of 12 available
columns you wish to span. For example, three equal columns would
use three .col-sm-4
Basic Structure of a Bootstrap Grid
The following is a basic structure of a Bootstrap grid:
<div class="container">
<div class="row">
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
...
</div>
</div>
So, to create the layout you want, create a container
(<div class="container">). Next, create a row (<div class="row">). Then,
add the desired number of columns (tags with appropriate .col-*-* classes).
Note that numbers in .col-*-* should always add up to 12 for each row.
Grid Options
The following table summarizes how the Bootstrap grid system works across
multiple devices:
Extra small
devices
Phones
(<768px)
Small devices
Tablets (>=768px)
Medium devices
Desktops
(>=992px)
Large devices
Desktops
(>=1200px)
Grid
behaviour
Horizontal at all
times
Collapsed to start,
horizontal above
breakpoints
Collapsed to start,
horizontal above
breakpoints
Collapsed to start,
horizontal above
breakpoints
Container
width
None (auto) 750px 970px 1170px
Class prefix .col-xs- .col-sm- .col-md- .col-lg-
Number of
columns
12 12 12 12
Column
width
Auto ~62px ~81px ~97px
Gutter
width
30px (15px on
each side of a
column)
30px (15px on
each side of a
column)
30px (15px on
each side of a
column)
30px (15px on each
side of a column)
Nestable Yes Yes Yes Yes
Offsets Yes Yes Yes Yes
Bootstrap Grid Example: Stacked-to-
horizontal
We will create a basic grid system that starts out stacked on mobiles/tablets
(small devices), before becoming horizontal on desktops (medium/large
devices).
The following example shows a simple "stacked-to-horizontal" two-column
layout:
Example: Stacked-to-horizontal
<div class="container">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-6" style="background-color:lavender;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor
incididunt ut labore et dolore magna aliqua. </p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut
aliquip ex ea commodo consequat. </p>
</div>
<div class="col-sm-6" style="background-color:lavenderblush;">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo
inventore
veritatis et quasi architecto beatae vitae dicta sunt
explicabo.</p>
</div>
</div>
</div>
Tip: The numbers in the .col-sm-* classes indicates how many columns the
div should span (out of 12). So, .col-sm-1 spans 1 column,
.col-sm-4 spans 4 columns, .col-sm-6 spans 6 columns, etc.
Note: Make sure that the sum always adds up to 12!
Tip: You can turn any fixed-width layout into a full-width layout by
changing the .container class to .container-fluid:
Example: Fluid container
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-6" style="background-color:lavender;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor
incididunt ut labore et dolore magna aliqua. </p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut
aliquip ex ea commodo consequat. </p>
</div>
<div class="col-sm-6" style="background-color:lavenderblush;">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo
inventore
veritatis et quasi architecto beatae vitae dicta sunt
explicabo.</p>
</div>
</div>
</div>
Bootstrap Grid Example: Small Devices
Assume we have a simple layout with two columns. We want the columns to
be split 25%/75% for small devices.
Tip: Small devices are defined as having a screen width from 768 pixels to
991 pixels.
For small devices we will use the .col-sm-* classes.
We will add the following classes to our two columns:
<div class="col-sm-3">....</div>
<div class="col-sm-9">....</div>
Now Bootstrap is going to say "at the small size, look for classes with -sm- in
them and use those".
The following example will result in a 25%/75% split on small devices:
Example
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-3" style="background-color:lavender;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor
incididunt ut labore et dolore magna aliqua. </p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullam co
laboris nisi ut
aliquip ex ea commodo consequat. </p>
</div>
<div class="col-sm-9" style="background-color:lavenderblush;">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo
inventore
veritatis et quasi architecto beatae vitae dicta sunt
explicabo.</p>
</div>
</div>
</div>
Note: Make sure that the sum always adds up to 12.
Bootstrap Grid Example: Medium Devices
In the previous chapter, we presented a grid example with classes for small
devices. We used two divs (columns) and we gave them a 25%/75% split:
<div class="col-sm-3">....</div>
<div class="col-sm-9">....</div>
But on medium devices the design may be better as a 50%/50% split.
Tip: Medium devices are defined as having a screen width from 992 pixels to
1199 pixels.
For medium devices we will use the .col-md-* classes.
Now we will add the column widths for medium devi ces:
<div class="col-sm-3 col-md-6">....</div>
<div class="col-sm-9 col-md-6">....</div>
Now Bootstrap is going to say "at the small size, look at classes with -sm- in
them and use those. At the medium size, look at classes with -md- in them
and use those".
The following example will result in a 25%/75% split on small devices and a
50%/50% split on medium devices:
Example
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-3 col-md-6" style="background-color:lavender;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor
incididunt ut labore et dolore magna aliqua. </p>
<p> Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut
aliquip ex ea commodo consequat. </p>
</div>
<div class="col-sm-9 col-md-6" style="background-
color:lavenderblush;">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo
inventore
veritatis et quasi architecto beatae vitae dicta sunt
explicabo.</p>
</div>
</div>
</div>
Note: Make sure that the sum always adds up to 12.
Bootstrap Grid Example: Large Devices
In the previous chapter, we presented a grid example with classes for small
and medium devices. We used two divs (columns) and we gave them a
25%/75% split on small devices, and a 50%/50% split on medium devices:
<div class="col-sm-3 col-md-6">....</div>
<div class="col-sm-9 col-md-6">....</div>
But on large devices the design may be better as a 33%/66% split.
Tip: Large devices are defined as having a screen width from 1200 pixels
and above.
For large devices we will use the .col-lg-* classes.
So now we will add the column widths for large devices:
<div class="col-sm-3 col-md-6 col-lg-4">....</div>
<div class="col-sm-9 col-md-6 col-lg-8">....</div>
Now Bootstrap is going to say "at the small size, look at classes with -sm- in
them and use those. At the medium size, look at classes with -md- in them
and use those. At the large size, look at classes with the word -lg- in them
and use those".
The following example will result in a 25%/75% split on small devices, a
50%/50% split on medium devices, and a 33%/66% split on large devices:
Example
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4" style="background-
color:lavender;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor
incididunt ut labore et dolore magna aliqua. </p>
<p> Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut
aliquip ex ea commodo consequat. </p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8" style="background-
color:lavenderblush;">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo
inventore
veritatis et quasi architecto beatae vitae dicta sunt
explicabo.</p>
</div>
</div>
</div>
Note: Make sure that the sum always adds up to 12.