Introduction
Create functional and responsive layouts easily using Natura11y's CSS Grid component.
CSS Grid
Natura11y's CSS Grid component offers essential layout options through utility classes.
Attempting to reproduce the limitless layout options available with CSS Grid Layout would be altogether misguided. You can and should create grid layouts yourself—writing custom CSS—alongside Natura11y's styles.
With that out of the way, let's look at the .grid
component beginning with Figure 6.
Line # | Details |
---|---|
1 | The parent It applies the css grid specification. |
3-13 | All direct children of the |
Grid Columns
To create columns within a .grid
selector, use the .grid--column-{x}
modifier, where x represents the number of columns (from 1 to 12).
For example, in Figure 7, the .grid--column-3
class creates a three-column grid.
Column Span
Grid items can span multiple columns within their parent .grid--column-{x}
selector. Use the .grid__colspan-{x}
modifier to specify the number of columns the item should span (from 2 to 12).
Grid Rows
Rows in the grid component are automatically created. Grid items can span up to 6 rows by using the .grid__rowspan-{x}
modifier, where x represents the number of rows (from 2 to 6). See Figure 9, line 3.
Breakpoint Modifiers
All column and row utilities in .grid
support breakpoint modifiers.
For responsive layouts, add a breakpoint modifier (e.g., .grid--column-{x}--{y}
) where x is the column count and y is the desired breakpoint.
For instance, to create a three-column layout at the medium breakpoint, use .grid--column-3--md
(Figure 10, line 1).
Grid Divider Modifier
You can add horizontal and vertical borders between grid cells by applying the .grid--divider
modifier class to .grid
selectors.
You can specify which axis (x or y) has continuous lines. Chain --fill-x
or --fill-y
modifiers to .grid--divider
. With .grid--divider--fill-x
present on the example in Figure 11, the horizontal lines run through.
With .grid--divider--fill-y
present on the example in Figure 12, the vertical lines run through.
The .grid--divider
modifier class adds borders using pseudo-elements on each of its direct children or cells. For this reason, when its child has overflow: hidden;
CSS property applied, such as with backdrops, for example, that child's border would not appear.
To remedy this, simply nest each child of .grid--divider
in a containing element. You could use a <ul>
tag with <li>
children, as shown in Figure 13:
Gap Utilities
Apply Natura11y's gap utilites to .grid
selectors to add space between grid items.
The .grid
selector with .gap-2
applied:
01
02
03
04
05
06
Order Utilities
Change the layout order of grid items.
Breakpoint Modifiers
Order utilities accept breakpoint modifiers.