Flexbox Grid
Create a fully responsive, fluid and nestable grid layout.
Atomic's grid system follows the mobile-first approach, accommodates up to 10 grid columns and is built using flexbox.
For explicit control over the widths and responsiveness, use the Size component.
Features
Grid systems usually come with a myriad of sizing options, but the vast majority of the time you just want two or three elements side-by-side. Given this, why should we be required to put sizing classes on every single cell?
Listed below are some of my criteria for an ideal grid system. Fortunately, with Flexbox we get most of these features for free.
- By default, each grid cell is the same width and height as every other cell in the row. Basically they all size to fit by default.
- For finer control, you can add sizing classes to individual cells. Without these classes, the cells simply divide up the available space as usual.
- For responsive grids, you can add media query-specific classes to the cells.
- Individual cells can be aligned vertically to the top, bottom, or middle.
- When you want all of the cells in a grid to have the same sizing, media, or alignment values, you should be able to just add a single class to the container to avoid unnecessary repetition.
- Grids can be nested as many levels deep as needed.
Usage
Basic grids
The grid cells below do not specify any widths, they just naturally space themselves equally and expand to fit the entire row. They’re also equal height by default.
Individual sizing
When equal widths aren’t what you want, you can add sizing classes to individual cells. Cells without sizing classes simply divide up the remaining space as normal.
The cells below labeled “auto” do not have sizing classes specified.
Responsive
Responsive Grids work by adding media classes to the Grid cells or containers. When those media values are met, the grids automatically adjust accordingly.
The cells below should be full width by default and scaled to fit above 768px
(`md` breakpoint). Resize your browser to see them in action.
Grid-ception!
Grid components are infinitely nestable inside other grid components.
Alignment features
Top-aligned grid cells
Bottom-aligned grid cells
Vertically centred grid cells
Mixed vertical alignment
Equal size column layouts
1 of 2
1 of 3
1 of 4
1 of 5
<div class="o-flex-grid">
<div class="o-flex-grid__cell">…</div>
<div class="o-flex-grid__cell">…</div>
<div class="o-flex-grid__cell">…</div>
</div>
Classes
Class | Description | Type |
---|---|---|
.o-flex-grid |
Object component | Component |
.o-flex-grid--full |
Stacks all grid cells (ready to be over-ridden with responsive modifiers) | Component modifier |
.o-flex-grid--flexCells |
All grid cells will fill the available vertical space (vertical alignment) | Component modifier |
.o-flex-grid--top |
Vertically aligns all grid cells to the top | Component modifier |
.o-flex-grid--bottom |
Vertically aligns all grid cells to the bottom | Component modifier |
.o-flex-grid--center |
Vertically aligns all grid cells to the center | Component modifier |
.o-flex-grid--justifyCenter |
Horizontally aligns the grid cells to the center | Component modifier |
.o-flex-grid--reverse |
Reverses the order of the grid cells | Component modifier |
.o-flex-grid--1of2 |
Divides grid cells into 2 columns per row | Component modifier |
.o-flex-grid--1of3 |
Divides grid cells into 3 columns per row | Component modifier |
.o-flex-grid--1of4 |
Divides grid cells into 4 columns per row | Component modifier |
.o-flex-grid--1of5 |
Divides grid cells into 5 columns per row | Component modifier |
.o-flex-grid@sm |
This classname, combined with any of the modifiers associated with the o-flex-grid component, (e.g o-flex-grid@sm--reverse ) have the same effect but only at that particular breakpoint and above |
Responsive modifier |
.o-flex-grid@md |
As above | Responsive modifier |
.o-flex-grid@lg |
As above | Responsive modifier |
.o-flex-grid@xl |
As above | Responsive modifier |
.o-flex-grid@xxl |
As above | Responsive modifier |
.o-flex-grid__cell |
Grid cells | Sub-element |
.o-flex-grid__cell--top |
Vertically aligns individual grid cell to the top | Sub-element modifier |
.o-flex-grid__cell--bottom |
Vertically aligns individual grid cell to the bottom | Sub-element modifier |
.o-flex-grid__cell--center |
Vertically aligns individual grid cell to the centre | Sub-element modifier |
.o-flex-grid__cell--autoSize |
Instructs the individual grid cell to fill the available space | Sub-element modifier |