This module contains responsive float and width utilities to create a variety of grid layouts. Use this module in combination with layout, white space, and other utilities.
Start by using a .clearfix
container.
To optionally set a max-width, use a utility from the basscss-layout module.
The .mx-auto
utility sets margin left and right auto to center the container.
Float columns using the .col
style. This also sets box-sizing border-box for each column.
.col .col
Add column width utilities. The total column-width number should add up to 12.
.col.col-6 .col.col-6
Responsive Grid
Use breakpoint-prefixed column utilities to change the grid at different screen widths.
All breakpoint-based styles in Basscss follow the same naming convention.
Prefix | Description |
---|---|
(no prefix) | Not scoped to a breakpoint |
sm- | --breakpoint-sm (default: min-width 40em) |
md- | --breakpoint-md (default: min-width 52em) |
lg- | --breakpoint-lg (default: min-width 64em) |
Apply the grid from the small breakpoint and up with the .sm-col
and .sm-col-6
utilities.
.sm-col.sm-col-6 .sm-col.sm-col-6
Add width adjustments for larger breakpoints. Resize the viewport width of the browser to see the effect.
.sm-col.sm-col-6.md-col-5.lg-col-4 .sm-col.sm-col-6.md-col-7.lg-col-8
Gutters
Use padding and negative margin utilities to create gutters based on the white space scale. The negative margin ensures content inside each column lines up with content outside of the grid. When using negative margin, be sure to compensate for the extra width created with a padded parent element or by using overflow hidden. Otherwise, horizontal scrolling may occur.
Create gutters with a width of 2 units using .mxn2
and .px2
.
.px2 .px2
For larger or smaller gutters, use any other step on the white space scale.
.px1 .px1 .px3 .px3
Nesting
Nest entire grid structures within columns to created nested grids.
Unnested Nested Nested
Reversed
To reverse the order of columns, use the .col-right
class to float columns right.
.col-right.col-6 .col.col-6
Centering Columns
Use the .mx-auto
class to center columns within their containers.
Centered Column
Breakpoint Based Floats
Column float utilities can be used independently of width utilities to control floating at different breakpoints. This example demonstrates a responsive media object.
.sm-col .overflow-hidden
Width Utilities
Column width utilities can also be used independently to add percentage based widths to any block or inline-block element.
.sm-col-6.md-col-4 Bacon ipsum dolor sit amet chuck prosciutto landjaeger ham hock filet mignon shoulder hamburger pig venison. Ham bacon corned beef, sausage kielbasa flank tongue pig drumstick capicola swine short loin ham hock kevin.