TGAM Flexbox Grid | The Globe and Mail Pattern Library

Grid

Auto-layout columns

Utilize breakpoint-specific column classes for equal-width columns. Add any number of unit-less classes for each breakpoint you need and every column will be the same width.

Equal-width

For example, here are two grid layouts that apply to every device and viewport, from xs to lg.

1 of 2
1 of 2
1 of 3
1 of 3
1 of 3

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col"> 1 of 2 </div> <div class="l-col"> 1 of 2 </div> </div> <div class="l-row"> <div class="l-col"> 1 of 3 </div> <div class="l-col"> 1 of 3 </div> <div class="l-col"> 1 of 3 </div> </div> </div>

Setting one column width

Auto-layout for flexbox grid columns also means you can set the width of one column and the others will automatically resize around it. You may use predefined grid classes (as shown below), grid mixins, or inline widths. Note that the other columns will resize no matter the width of the center column.

1 of 3 (auto)
2 of 3 (fixed)
3 of 3 (auto)
1 of 3 (auto)
2 of 3 (fixed)
3 of 3 (auto)

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col"> 1 of 3 (auto) </div> <div class="l-col-md-5"> 2 of 3 (fixed) </div> <div class="l-col"> 3 of 3 (auto) </div> </div> <div class="l-row"> <div class="l-col"> 1 of 3 (auto) </div> <div class="l-col-md-4"> 2 of 3 (fixed) </div> <div class="l-col"> 3 of 3 (auto) </div> </div> </div>

Variable width content

Using the l-col-{breakpoint}-auto classes, columns can size itself based on the natural width of its content. This is super handy with single line content like inputs, numbers, etc. This, in conjunction with horizontal alignment classes, is very useful for centering layouts with uneven column sizes as viewport width changes.

1 of 3
Variable width content
3 of 3
1 of 3
Variable width content
3 of 3

HTML

<div class="l-container"> <div class="l-row u-justify-content-md-center"> <div class="l-col l-col-lg-2"> 1 of 3 </div> <div class="l-col-lg-2 l-col-md-auto"> Variable width content </div> <div class="l-col l-col-lg-2"> 3 of 3 </div> </div> <div class="l-row"> <div class="l-col"> 1 of 3 </div> <div class="l-col-lg-2 l-col-md-auto"> Variable width content </div> <div class="l-col l-col-lg-2"> 3 of 3 </div> </div> </div>

Equal-width multi-row

Create equal-width columns that span multiple rows by inserting a div where you want the columns to break to a new line. Make the breaks responsive by mixing the div with some responsive display utilities.

l-col
l-col
l-col
l-col

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col">l-col</div> <div class="l-col">l-col</div> <div style="width: 100%;"></div> <div class="l-col">l-col</div> <div class="l-col">l-col</div> </div> </div>

Responsive classes

The grid includes four tiers of predefined classes for building complex responsive layouts. Customize the size of your columns on extra small, small, medium, or large devices however you see fit.

All breakpoints

For grids that are the same from the smallest of devices to the largest, use the .l-col and .l-col-* classes. Specify a numbered class when you need a particularly sized column; otherwise, feel free to stick to .l-col.

l-col
l-col
l-col
l-col
l-col-sm
l-col-sm
l-col-sm
l-col-sm
l-col-md
l-col-md
l-col-md
l-col-md
l-col-lg
l-col-lg
l-col-lg
l-col-lg

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col">l-col</div> <div class="l-col">l-col</div> <div class="l-col">l-col</div> <div class="l-col">l-col</div> </div> <div class="l-row"> <div class="l-col-sm">l-col-sm</div> <div class="l-col-sm">l-col-sm</div> <div class="l-col-sm">l-col-sm</div> <div class="l-col-sm">l-col-sm</div> </div> <div class="l-row"> <div class="l-col-md">l-col-md</div> <div class="l-col-md">l-col-md</div> <div class="l-col-md">l-col-md</div> <div class="l-col-md">l-col-md</div> </div> <div class="l-row"> <div class="l-col-lg">l-col-lg</div> <div class="l-col-lg">l-col-lg</div> <div class="l-col-lg">l-col-lg</div> <div class="l-col-lg">l-col-lg</div> </div> </div>

Stacked to horizontal

Using a single set of .l-col-sm-* classes, you can create a basic grid system that starts out stacked on extra small devices before becoming horizontal on desktop (medium) devices.

l-col l-col-sm-4 l-col-lg-8
l-col l-col-sm-4 l-col-lg-8
l-col-1 l-col-sm-4 l-col-lg-8
l-col-1 l-col-sm-4 l-col-lg-8
l-col-1 l-col-sm-6 l-col-md-4 l-col-lg-10
l-col-1 l-col-sm-2 l-col-md-8 l-col-lg-6

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col l-col-sm-4 l-col-md-6 l-col-lg-8">l-col l-col-sm-4 l-col-lg-8</div> <div class="l-col l-col-sm-4 l-col-md-6 l-col-lg-8">l-col l-col-sm-4 l-col-lg-8</div> </div> <div class="l-row"> <div class="l-col-1 l-col-sm-4 l-col-md-6 l-col-lg-8">l-col-1 l-col-sm-4 l-col-lg-8</div> <div class="l-col-1 l-col-sm-4 l-col-md-6 l-col-lg-8">l-col-1 l-col-sm-4 l-col-lg-8</div> </div> <div class="l-row"> <div class="l-col-1 l-col-sm-6 l-col-md-4 l-col-lg-10">l-col-1 l-col-sm-6 l-col-md-4 l-col-lg-10</div> <div class="l-col-1 l-col-sm-2 l-col-md-8 l-col-lg-6">l-col-1 l-col-sm-2 l-col-md-8 l-col-lg-6</div> </div> </div>

Alignment

Use flexbox alignment utilities to vertically and horizontally align columns.

Vertical alignment

One of three columns
Bigger column
One of three columns
One of three columns
Bigger column
One of three columns
One of three columns
Bigger column
One of three columns

HTML

<div class="l-container"> <div class="l-row u-align-items-start"> <div class="l-col"> One of three columns </div> <div class="l-col" style="height: 4em;"> Bigger column </div> <div class="l-col"> One of three columns </div> </div> <div class="l-row u-align-items-center"> <div class="l-col"> One of three columns </div> <div class="l-col" style="height: 4em;"> Bigger column </div> <div class="l-col"> One of three columns </div> </div> <div class="l-row u-align-items-end"> <div class="l-col"> One of three columns </div> <div class="l-col" style="height: 4em;"> Bigger column </div> <div class="l-col"> One of three columns </div> </div> </div>
One of three columns
One of three columns
One of three columns

HTML

<div class="l-container"> <div class="l-row" style="min-height: 4em;"> <div class="l-col u-align-self-start"> One of three columns </div> <div class="l-col u-align-self-center"> One of three columns </div> <div class="l-col u-align-self-end"> One of three columns </div> </div> </div>

Horizontal alignment

One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns
One of two columns

HTML

<div class="l-container"> <div class="l-row u-justify-content-start"> <div class="l-col-sm-2"> One of two columns </div> <div class="l-col-sm-2"> One of two columns </div> </div> <div class="l-row u-justify-content-center"> <div class="l-col-sm-2"> One of two columns </div> <div class="l-col-sm-2"> One of two columns </div> </div> <div class="l-row u-justify-content-end"> <div class="l-col-sm-2"> One of two columns </div> <div class="l-col-sm-2"> One of two columns </div> </div> <div class="l-row u-justify-content-around"> <div class="l-col-sm-2"> One of two columns </div> <div class="l-col-sm-2"> One of two columns </div> </div> <div class="l-row u-justify-content-between"> <div class="l-col-sm-2"> One of two columns </div> <div class="l-col-sm-2"> One of two columns </div> </div> </div>

No column gutters

The gutters between columns in our predefined grid classes can be removed with .l-row--gutters-none for XS tier, or .l-row-*-gutters-none or other tiers. This removes the negative margins from .row and the horizontal padding from all immediate children columns.

Here’s the source code for creating these styles. Note that column overrides are scoped to only the first children columns and are targeted via attribute selector. While this generates a more specific selector, column padding can still be further customized with spacing utilities.

In practice, here’s how it looks. Note you can continue to use this with all other predefined grid classes (including column widths, responsive tiers, reorders, and more).

ALL no gutters
SM - no gutters
MD - no gutters
LG - no gutters

HTML

<div class="l-container"> <div class="l-row l-row--gutters-none"> <div class="l-col">ALL no gutters</div> </div> <div class="l-row l-row-sm--gutters-none"> <div class="l-col">SM - no gutters</div> </div> <div class="l-row l-row-md--gutters-none"> <div class="l-col">MD - no gutters</div> </div> <div class="l-row l-row-lg--gutters-none"> <div class="l-col">LG - no gutters</div> </div> </div>
A - no/default gutters
B - no left gutter
C - no right gutter
D - yes gutters

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col l-col--gutters-none l-col-sm-gutters-default l-col-md-gutters-none l-col-lg-gutters-default">A - no/default gutters</div> <div class="l-col l-col--gutters-left-none l-col-lg-gutters-left-none">B - no left gutter</div> </div> <div class="l-row"> <div class="l-col l-col--gutters-right-none l-col-lg-gutters-right-none">C - no right gutter</div> <div class="l-col">D - yes gutters</div> </div> </div>

Column wrapping

If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.

l-col-md-9
l-col-md-4
Since 9 + 4 = 13 (greater than) 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.
l-col-md-6
Subsequent columns continue along the new line.

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col-md-9">l-col-md-9</div> <div class="l-col-md-4">l-col-md-4<br>Since 9 + 4 = 13 (greater than) 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div> <div class="l-col-md-6">l-col-md-6<br>Subsequent columns continue along the new line.</div> </div> </div>

Column resets

With the handful of grid tiers available, you’re bound to run into issues where, at certain breakpoints, your columns don’t clear quite right as one is taller than the other. To fix that, use a combination of a .l-row-clearfix and our responsive utility classes.

l-col-1 l-col-md
l-col-1 l-col-md
l-col-1 l-col-md
l-col-1 l-col-md
l-col-1 l-col-md
l-col-1 l-col-md

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col-1 l-col-md">l-col-1 l-col-md</div> <div class="l-col-1 l-col-md">l-col-1 l-col-md</div> <!-- Add the extra clearfix for only the required viewport --> <div class="d-hidden-sm-down l-row-clearfix"></div> <div class="l-col-1 l-col-md">l-col-1 l-col-md</div> <div class="l-col-1 l-col-md">l-col-1 l-col-md</div> <!-- Add the extra clearfix for only the required viewport --> <div class="d-hidden-sm-down l-row-clearfix"></div> <div class="l-col-1 l-col-md">l-col-1 l-col-md</div> <div class="l-col-1 l-col-md">l-col-1 l-col-md</div> </div> </div>

Reordering

Flex order

Use flexbox utilities for controlling the visual order of your content.

First, but unordered
Second, but last
Third, but first

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col u-flex-unordered"> First, but unordered </div> <div class="l-col u-flex-last"> Second, but last </div> <div class="l-col u-flex-first"> Third, but first </div> </div> </div>

Offsetting columns

Move columns to the right using .l-offset-md-* classes. These classes increase the left margin of a column by * columns. For example, .l-offset-md-4 moves .l-col-md-4 over four columns.

l-col-md-4
l-col-md-4 l-offset-md-4
l-col-md-3 l-offset-md-3
l-col-md-3 l-offset-md-3
l-col-md-6 l-offset-md-3
l-col-lg-10 l-offset-lg-1

HTML

<div class="l-container--overlay"> <div class="l-container"> <div class="l-row"> <div class="l-col-md-4">l-col-md-4</div> <div class="l-col-md-4 l-offset-md-4">l-col-md-4 l-offset-md-4</div> </div> <div class="l-row"> <div class="l-col-md-3 l-offset-md-3">l-col-md-3 l-offset-md-3</div> <div class="l-col-md-3 l-offset-md-3">l-col-md-3 l-offset-md-3</div> </div> <div class="l-row"> <div class="l-col-md-6 l-offset-md-3">l-col-md-6 l-offset-md-3</div> </div> <div class="l-row"> <div class="l-col-lg-10 l-offset-lg-1">l-col-lg-10 l-offset-lg-1</div> </div> </div> </div>

Push and pull

Easily change the order of our built-in grid columns with .l-push-md-* and .l-pull-md-* modifier classes.

l-col-md-9 l-push-md-3
l-col-md-3 l-pull-md-9

HTML

<div class="l-container--overlay"> <div class="l-container"> <div class="l-row"> <div class="l-col-md-9 l-push-md-3">l-col-md-9 l-push-md-3</div> <div class="l-col-md-3 l-pull-md-9">l-col-md-3 l-pull-md-9</div> </div> </div> </div>

Nesting

To nest your content with the default grid, add a new .l-row and set of .l-col-sm-* columns within an existing .l-col-sm-* column.

Level 1a: l-col-sm-8
Level 2a: l-col-sm-4
Level 2b: l-col-sm-4
Level 1b: l-col

HTML

<div class="l-container"> <div class="l-row"> <div class="l-col-sm-8"> Level 1a: l-col-sm-8 <div class="l-row"> <div class="l-col-sm-4"> Level 2a: l-col-sm-4 </div> <div class="l-col-sm-4"> Level 2b: l-col-sm-4 </div> </div> </div> <div class="l-col"> Level 1b: l-col </div> </div> </div>

▲ TOP