{{_i}}Bootstrap is built on a responsive 12-column grid. We've also included fixed- and fluid-width layouts based on that system.{{/i}}
{{_i}}Bootstrap makes use of HTML elements and CSS properties that require the use of the HTML5 doctype. Be sure to include it at the beginning of every Bootstrapped page in your project.{{/i}}
<!DOCTYPE html> <html lang="en"> ... </html>
{{_i}}Within the scaffolding.less file, we set basic global display, typography, and link styles. Specifically, we:{{/i}}
background-color: white;
on the body
{{/i}}@baseFontFamily
, @baseFontSize
, and @baseLineHeight
attributes as our typographyic base{{/i}}@linkColor
and apply link underlines only on :hover
{{/i}}{{_i}}As of Bootstrap 2, the traditional CSS reset has evolved to make use of elements from Normalize.css, a project by Nicolas Gallagher that also powers the HTML5 Boilerplate.{{/i}}
{{_i}}The new reset can still be found in reset.less, but with many elements removed for brevity and accuracy.{{/i}}
{{_i}}The default grid system provided as part of Bootstrap is a 940px-wide, 12-column grid.{{/i}}
{{_i}}It also has four responsive variations for various devices and resolutions: phone, tablet portrait, table landscape and small desktops, and large widescreen desktops.{{/i}}
<div class="row"> <div class="span4">...</div> <div class="span8">...</div> </div>
{{_i}}As shown here, a basic layout can be created with two "columns," each spanning a number of the 12 foundational columns we defined as part of our grid system.{{/i}}
<div class="row"> <div class="span4">...</div> <div class="span4 offset4">...</div> </div>
{{_i}}With the static (non-fluid) grid system in Bootstrap, nesting is easy. To nest your content, just add a new .row
and set of .span*
columns within an existing .span*
column.{{/i}}
{{_i}}Nested rows should include a set of columns that add up to the number of columns of it's parent. For example, two nested .span3
columns should be placed within a .span6
.{{/i}}
<div class="row"> <div class="span12"> {{_i}}Level 1 of column{{/i}} <div class="row"> <div class="span6">{{_i}}Level 2{{/i}}</div> <div class="span6">{{_i}}Level 2{{/i}}</div> </div> </div> </div>
{{_i}}The fluid grid system uses percents for column widths instead of fixed pixels. It also has the same responsive variations as our fixed grid system, ensuring proper proportions for key screen resolutions and devices.{{/i}}
{{_i}}Make any row fluid simply by changing .row
to .row-fluid
. The columns stay the exact same, making it super straightforward to flip between fixed and fluid layouts.{{/i}}
<div class="row-fluid"> <div class="span4">...</div> <div class="span8">...</div> </div>
{{_i}}Nesting with fluid grids is a bit different: the number of nested columns doesn't need to match the parent. Instead, your columns are reset at each level because each row takes up 100% of the parent column.{{/i}}
<div class="row-fluid"> <div class="span12"> {{_i}}Level 1 of column{{/i}} <div class="row-fluid"> <div class="span6">{{_i}}Level 2{{/i}}</div> <div class="span6">{{_i}}Level 2{{/i}}</div> </div> </div> </div>
{{_i}}Variable{{/i}} | {{_i}}Default value{{/i}} | {{_i}}Description{{/i}} |
---|---|---|
@gridColumns |
12 | {{_i}}Number of columns{{/i}} |
@gridColumnWidth |
60px | {{_i}}Width of each column{{/i}} |
@gridGutterWidth |
20px | {{_i}}Negative space between columns{{/i}} |
@siteWidth |
{{_i}}Computed sum of all columns and gutters{{/i}} | {{_i}}Counts number of columns and gutters to set width of the .container-fixed() mixin{{/i}} |
{{_i}}Built into Bootstrap are a handful of variables for customizing the default 940px grid system, documented above. All variables for the grid are stored in variables.less.{{/i}}
{{_i}}Modifying the grid means changing the three @grid*
variables and recompiling Bootstrap. Change the grid variables in variables.less and use one of the four ways documented to recompile. If you're adding more columns, be sure to add the CSS for those in grid.less.{{/i}}
{{_i}}Customization of the grid only works at the default level, the 940px grid. To maintain the responsive aspects of Bootstrap, you'll also have to customize the grids in responsive.less.{{/i}}
{{_i}}The default and simple 940px-wide, centered layout for just about any website or page provided by a single <div class="container">
.{{/i}}
<body> <div class="container"> ... </div> </body>
{{_i}}<div class="container-fluid">
gives flexible page structure, min- and max-widths, and a left-hand sidebar. It's great for apps and docs.{{/i}}
<div class="container-fluid"> <div class="row-fluid"> <div class="span2"> <!--{{_i}}Sidebar content{{/i}}--> </div> <div class="span10"> <!--{{_i}}Body content{{/i}}--> </div> </div> </div>
{{_i}}Bootstrap supports a handful of media queries in a single file to help make your projects more appropriate on different devices and screen resolutions. Here's what's included:{{/i}}
{{_i}}Label{{/i}} | {{_i}}Layout width{{/i}} | {{_i}}Column width{{/i}} | {{_i}}Gutter width{{/i}} |
---|---|---|---|
{{_i}}Smartphones{{/i}} | 480px and below | {{_i}}Fluid columns, no fixed widths{{/i}} | |
{{_i}}Portrait tablets{{/i}} | 480px to 768px | {{_i}}Fluid columns, no fixed widths{{/i}} | |
{{_i}}Landscape tablets{{/i}} | 768px to 979px | 42px | 20px |
{{_i}}Default{{/i}} | 980px and up | 60px | 20px |
{{_i}}Large display{{/i}} | 1210px and up | 70px | 30px |
{{_i}}To ensure devices display responsive pages properly, include the viewport meta tag.{{/i}}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{_i}}Media queries allow for custom CSS based on a number of conditions—ratios, widths, display type, etc—but usually focuses around min-width
and max-width
.{{/i}}
{{_i}}Bootstrap doesn't automatically include these media queries, but understanding and adding them is very easy and requires minimal setup. You have a few options for including the responsive features of Bootstrap:{{/i}}
{{_i}}Why not just include it? Truth be told, not everything needs to be responsive. Instead of encouraging developers to remove this feature, we figure it best to enable it.{{/i}}
// {{_i}}Landscape phones and down{{/i}} @media (max-width: 480px) { ... } // {{_i}}Landscape phone to portrait tablet{{/i}} @media (max-width: 768px) { ... } // {{_i}}Portrait tablet to landscape and desktop{{/i}} @media (min-width: 768px) and (max-width: 980px) { ... } // {{_i}}Large desktop{{/i}} @media (min-width: 1200px) { .. }