Grid
Usage
A grid provides a structure of rows and columns for aligning content. Grids are useful because they help create a familiar and easily navigable structure for content.
Clarity extends the 12-column Bootstrap 4 Flex Grid and prefixes the grid classes with clr-. Prefixing allows us to avoid conflicting with other grid systems. However, it also means if you are familiar with the grid classes in Bootstrap 4, the Clarity grid will be familiar.
Important features about the grid are listed below:
Grid Behavior
Horizontal for extra-small. All other breakpoints are collapsed to start, then horizontal above the breakpoint.
Common Properties
- Number of columns: 12
- Gutter width: 24px (12px on the left and right of column)
- All columns support nesting, offsets, and column order
Extra small < 576px | .clr-col- |
---|---|
Small ≥ 576px | .clr-col-sm- |
Medium ≥ 768px | .clr-col-md- |
Large ≥ 992px | .clr-col-lg- |
Extra large ≥ 1200px | .clr-col-xl- |
Rows
A .clr-row
is a horizontal group of 12 columns.
Columns
The column classes specify the number of columns per row. The value appended to the class prefix must be between 1 and 12.
Column Stacking
Grid columns can occupy different widths on different device sizes.
In the example below, if the device size is ≥ 768px (medium or above), the grid has two columns of equal width and a third column that occupies the entire width of the row. For device sizes < 768px, each column occupies the entire width of the row and the columns are stacked. Resize your browser to see how this works.
Column Wrapping
Placing more than 12 columns in a single row will wrap the columns exceeding the row, as one unit, onto a new line.
Flexbox Grid Layout
Equal Width
Using the .clr-col-*
class divides the row into equal width columns.
Setting One Column Width
A specific width can be assigned to a column. All the siblings of that columns will automatically resize around it.
Variable Width Content
Using the .clr-col-*-auto
class on a column sizes it based on the width of its content.
Multi Row
Using the .clr-break-row
class after a column, breaks the following columns to a new line.
Column Offsets
The responsive clr-offset-*
classes increase a column’s left margin by * number of columns.
Vertical Alignment in Rows
Columns within a row can be vertically aligned using the following responsive classes:
- clr-align-items-*-start
- clr-align-items-*-center
- clr-align-items-*-end
Start
Start
Center
Center
End
End
A column can individually be vertically aligned in a row using the following responsive classes:
- clr-align-self-*-start
- clr-align-self-*-center
- clr-align-self-*-end
1/31/31/3
Horizontal Alignment in Rows
To align columns horizontally within a row, extend the row with one of the following responsive classes:
- clr-justify-content-*-start
- clr-justify-content-*-center
- clr-justify-content-*-end
- clr-justify-content-*-around
- clr-justify-content-*-between
Start
Start
Center
Center
End
End
Content Around
Space Around
Content Between
Space Between
Grid Nesting
Usage
Clarity recommends that your application layout stay on the grid. A grid-based approach:
- Aligns content consistently
- Establishes a foundation that can be easily built upon for future designs
- Simplifies layout decisions required of a designer
- Coordinates the efforts of multiple designers
Applying the Grid
Apply the grid with consideration of content. Some pages might benefit from a three-column layout, where other pages might work best with a two-column layout.
You can vary the column layout within the same page. This strategy works well for presenting content that scrolls vertically.
Don’t lock your design into a layout optimized for a large window.
Grids and Card Layouts
Designing to a grid is especially important for card layouts. Cards contains blocks of content and their height and width can vary. The grid aligns the cards in a way that is easy for users to navigate.
Custom Grids
If You Decide Not to Conform to the Grid Do so with intent. Find a balance between aesthetics and conformity. Keep in mind that elements that are not aligned to the grid draw attention in the same way as color, contrast, and iconography and require more cognitive effort on the part of the user.