

Equal-widthįor example, here are two grid layouts that apply to every device and viewport, from xs to xl.

Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like. See how aspects of the Bootstrap grid system work across multiple devices with a handy table. This is because the viewport width is in pixels and does not change with the font size. While Bootstrap uses ems or rems for defining most sizes, pxs are used for grid breakpoints and container widths. Those columns are centered in the page with the parent. The above example creates three equal-width columns on small, medium, large, and extra large devices using our predefined grid classes. The dark green represents padding on either side of the column, undoing the negative margin on the row and bringing the content back into alignment with the grid.One of three columns One of three columns One of three columns The light green is where content will go. In this example we want our content to be only half the width of the container (6 out of a possible 12 columns wide). The numbers at the end of each class name represent the number of columns that the column.

The Bootstrap grid system can have up to 12 columns, and you can specify how these columns scale for different viewport sizes. Grid systems enable you to create advanced layouts using rows and columns. That negative margin is why columns must be the direct descendants of rows: Bootstrap grids are the easiest way to create layouts. I’ve highlighted this with red arrows that’s how important it is. This is important: the dark yellow area represents a negative margin on either side of the row that effectively negates the padding on the parent. The lighter yellow area again represents the space for your content. (And/or we want our content to be laid out differently on different screen sizes, but I’m not going to get into breakpoints here.) Let’s look at how rows and columns work. So when do we need rows and columns? When we want to split our content into columns.
BOOTSTRAP GRID CODE
If the code above were the first thing that appeared after the opening body tag, for instance, I would be concerned. I realized the usage of this example that truly bothers me is as a wrapper for the rest of the page’s content. This makes it easier to come back and add columns later, and it leads to cleaner code if you have several rows on the page, some of which contain only one column. It totally makes sense to me to write all your markup in the rows and columns structure. UPDATE: After talking to several colleagues who admitted they were “guilty” of doing this, I need to clarify that this is not a sin. But to me it often signals a lack of understanding. Having a row with only one full-width column inside it won’t hurt anything-it’s a technically valid use of the grid. This confusion leads to one of my pet peeves:
BOOTSTRAP GRID FULL
The dark blue area represents padding on either side of the container, about which we’ll learn more in just a minute.Īs you can see above, if your intention is for your content always to take up the full width of the container, there’s no need for rows or columns. The light blue area is where the content goes. What does this look like visually? I’m glad you asked. Column classes determine the width of the column.Content should be placed within columns, and only columns may be immediate children of rows.Containers center your site’s content in the browser window.There are three major components: containers, rows, and columns.I’ll paraphrase here, and encourage you to read the original: The Bootstrap docs lay out the system in pretty stark terms, but it’s hard to grok this without getting inside of it.

Instead of just grumbling about this (which I reserve the right to continue doing), I thought I would try to help unlock the relationship between containers, rows, and columns in hopes of improving both understanding and markup. Yet the grid system can present a steep learning curve, and many developers tend to just throw containers, rows, and columns into their pages without understand how these elements work together. The Bootstrap grid has been around in its current form since v3.0 in 2013, and (to our collective relief) remains the same in v.4.0. The most basic and powerful of these arguably is its mobile-first 12-column grid layout system. The seemingly inescapable CSS framework, has many valuable features. Bootstrap is a popular frontend open source toolkit.
