{{_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}}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}}
<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}}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 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 980px | 44px | 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) { .. }