CSS Grid

CSS Grid system is experimental and opt-in, use with care.

Examples

Three columns

Three equal-width columns across all viewports and devices can be created by using the .g-col-4 classes. Add responsive classes to change the layout by viewport size.

.g-col-4
.g-col-4
.g-col-4

Responsive

Use responsive classes to adjust your layout across viewports. Here we start with two columns on the narrowest viewports, and then grow to three columns on medium viewports and above.

.g-col-6 .g-col-md-4
.g-col-6 .g-col-md-4
.g-col-6 .g-col-md-4

Compare that to this two column layout at all viewports.

.g-col-6
.g-col-6

Wrapping

Grid items automatically wrap to the next line when there’s no more room horizontally. Note that the gap applies to horizontal and vertical gaps between grid items.

Also note that the gap is responsive. It changes in size based on the original grid settings. See the Gaps section bellow for more info.

.g-col-6
.g-col-6
.g-col-6
.g-col-6

Starts

Start classes aim to replace our default grid’s offset classes, but they’re not entirely the same. CSS Grid creates a grid template through styles that tell browsers to “start at this column” and “end at this column.” Those properties are grid-column-start and grid-column-end. Start classes are shorthand for the former. Pair them with the column classes to size and align your columns however you need. Start classes begin at 1 as 0 is an invalid value for these properties.

.g-col-3 .g-start-2
.g-col-4 .g-start-6

Auto columns

When there are no classes on the grid items (the immediate children of a .l-lta-grid), each grid item will automatically be sized to one column.

1
1
1
1
1
1
1
1
1
1
1
1

This behavior can be mixed with grid column classes.

.g-col-6
1
1
1
1
1
1

Nesting

Similar to our default grid system, our CSS Grid allows for easy nesting of .l-lta-grids. However, unlike the default, this grid inherits changes in the rows, columns, and gaps. Consider the example below:

  • We override the default number of columns with a local CSS variable: --lta-columns: 3.
  • In the first auto-column, the column count is inherited and each column is one-third of the available width.
  • In the second auto-column, we’ve reset the column count on the nested .l-lta-grid to 12 (our default).
  • The third auto-column has no nested content.

In practice this allows for more complex and custom layouts when compared to our default grid system.

First auto-column
Auto-column
Auto-column
Second auto-column
6 of 12
4 of 12
2 of 12
Third auto-column

Customizing

Customize the number of columns, the number of rows, and the width of the gaps with local CSS variables.

VariableFallback valueDescription
--lta-rows1The number of rows in your grid template
--lta-columns12The number of columns in your grid template
--lta-gap24pxThe size of the gap between columns (vertical and horizontal)

These CSS variables have no default value; instead, they apply fallback values that are used until a local instance is provided. For example, we use var(--lta-rows, 1) for our CSS Grid rows, which ignores --lta-rows because that hasn’t been set anywhere yet. Once it is, the .l-lta-grid instance will use that value instead of the fallback value of 1.

No grid classes

Immediate children elements of .l-lta-grid are grid items, so they’ll be sized without explicitly adding a .g-colclass.

Auto-column
Auto-column
Auto-column

Columns and gaps

Adjust the number of columns and the gap.

.g-col-2
.g-col-2
.g-col-6
.g-col-4

Adding rows

Adding more rows and changing the placement of columns:

Auto-column
Auto-column
Auto-column

Gaps

The gaps are responsive, it changes for each breakpoint based on the original grid. But you can override it using the settings bellow.

Change the vertical gaps only by modifying the row-gap. Note that we use gap on .l-lta-grids, but row-gap and column-gap can be modified as needed.

.g-col-6
.g-col-6
.g-col-6
.g-col-6

Because of that, you can have different vertical and horizontal gaps, which can take a single value (all sides) or a pair of values (vertical and horizontal). This can be applied with an inline style for gap, or with our --lta-gap CSS variable.

.g-col-6
.g-col-6
.g-col-6
.g-col-6

Columns

The .col-* (.col-{md, xl}-*) classes can be used to give an element a specific width.

The width is calculated using a gutter like this .col-6 { width: calc(50% - var(--lta-gap-{sm, md, xl}, 0px)) }. If we define the --lta-gap-{breakpoint} variable we can control the width taking into consideration gaps.

col-12 col-md-6 col-xl-4
col-12 col-md-6 col-xl-8