We have a standard 12 column grid for you available. You can do any combination of columns as long as the total of each (virtual) row is 12.
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-2
.col-2
.col-2
.col-2
.col-2
.col-2
.col-3
.col-3
.col-3
.col-3
.col-4
.col-4
.col-4
.col-5
.col-5
.col-2
.col-6
.col-6
.col-7
.col-5
.col-8
.col-4
.col-9
.col-3
.col-10
.col-2
.col-11
.col-1
Containers
When using grid for page layout, your grid will usually be nested inside a .container but you can also use grids in other modules without the .container.
It will calculate the widths based on the available width of its wrapper.
Grid vs. float-based columns
Back in the old days we used a .container with .row’s (to clear the floats). This is no longer needed.
Old school example code
Don't use this example
With CSS Grid Layout there’s no need to clear the floats and also no need to think one-dimensional with rows.
Modern example
Use this instead
This is done with pure CSS magic
Fallbacks for older browsers
If your browser doesn’t support display: grid; we automatically fall back to float based layout. Just make sure the total of columns, on each virtual row, is 12 so they wrap.
Only pitfall is when your columns don’t have equal heights, which happens quite regularly. With wrapping floats you can end up with a column being stuck by another one that’s higher.
Intentionally broken layout to emulate floats
.col-1
.col-1
.col-1
higher col breaks layout
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-8
.col-4
If you want to prevent this you need to add class .col--clear to each 13th col
Emulating floats: this grid doesn’t use display: grid; in the example below.
.col-1
.col-1
.col-1
higher col doesn't break layout
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-1
.col-8.col--clear
.col-4
.col-3.col--clear
.col-3
another higher col that doesn't break layout
.col-3
.col-5.col--clear
.col-5
.col-2
Grids and breakpoints
The default grid is completely fluid and has no breakpoints. If you need different behaviour across breakpoints add modifiers to .grid.
Selector
Breakpoint
.grid
Fully fluid across all breakpoints, even on small screens
.grid--small
Stacked blocks on really small screens, fluid grid from small breakpoint
.grid--medium
Stacked blocks on smaller screens, fluid grid from medium breakpoint
.col-6
.col-6
.col-6
.col-6
Offsetting columns
Offsetting columns in a CSS Grid is tricky. It works the other way around. Instead of defining how many cols there are between adjacent columns, the offset determines how many columns (starting from the outer left edge) should be skipped. So you’ll have to do some math yourself, knowing we have a total of 12 columns.
So if you give an offset of 8 with .col--grid-offset-8, your column will start on the 9th grid item, no matter if there are any other columns preceding. See example below.
1
2
3
.col-6.col--grid-offset-3
.col-3
1
2
.col-4.col--grid-offset-2
7
8
.col-3.col--grid-offset-8
12
If your math doesn’t work out and your offsets collide with grid items that are already occupied, the faulty one will wrap to a new row.
E.g. the 6th column is alreay occupied by the first box, and your second box has an offset of 5 ( = starting on the 6th column). He can’t construct that grid row, so he starts a new one. See example below
1
2
.col-4.col--grid-offset-2
7
8
9
10
11
12
1
2
3
4
5
.col-3.col--grid-offset-5
9
10
11
12
Offsets and float-based grids
If you have to support browsers that don’t understand CSS Grid Layout, you have to add an extra class. The offset calculation with this class is done the old-fashioned way. If you want an offset of 2 columns, you add .col--float-offset-2. No special math needed here.
1
2
3
.col-6.col--grid-offset-3
.col-3
1
2
.col-4.col--grid-offset-2.col--float-offset-2
7
8
.col-3.col--grid-offset-8.col--float-offset-2
12
Nested grids
Nested grids are supported. Go nuts!
.col-6 with a nested grid
.col-4
.col-4
.col-4
.col-6
Conclusion:
This is production ready code. Please use this in your project.