Foundations

Grid system

scss:Readyfigma:Ready

Flexy is a grid system and a general purpose layout tool based on Flex. It can be used to build page level layout as well as component level one. It is why it is not called "grid" but "flexy".

Get started

Import

@import 'settings-tools/all-settings';
@import 'layouts/_l.container'; // you generally want the container as well
@import 'layouts/_l.flexy';

How it works

The example below creates four equal-width columns at small, medium, large, and extra large breakpoints using our predefined grid classes.

Viewport: px
<div class="ml-container">
<div class="ml-flexy">
<div class="example ml-flexy__col">
Col 1
</div>
<div class="example ml-flexy__col">
Col 2
</div>
<div class="example ml-flexy__col">
Col 3
</div>
<div class="example ml-flexy__col">
Col 4
</div>
</div>
</div>
Container rules

ml-container defines the overall grid context at the top level and applies the proper margin and our default max-width. You can also remove this max width, by using the grid modifier class ml--container--fluid. See the default container.

Columns

ml-flexy__col defines individual columns inside the grid. With Flexbox columns widths are set in percentages relative to their parent element so columns without a specific width will automatically be equal. For example, four instances of ml-flexy__col will give you four equal width columns — each 25% of the parent from the small breakpoint on up.

Gutters

In most cases, you will need gutters.

When used with gutters, .ml-flexy uses the negative margin pattern: each column as a padding measuring half a gutter width, and the containing .ml-flexy as a negative margin equal to half a gutter width on both sides as well.

<div class="ml-flexy ml-flexy--gutter">
<div class="ml-flexy__col">
col 1
</div>
<div class="ml-flexy__col">
col 2
</div>
</div>

Tokens

Token nameDescriptionValue
size.gutter.screen.sThe gutter width for smallest devices and up1mu 16px
size.gutter.screen.mThe gutter width for screen m and up2mu 32px

Reminder: mu = MagicUnit. Ex: 3.5mu = MagicUnit \* 3.5

Columns options

Widths

You can apply specific columns width using .ml-flexy__col modifiers:

ModifierWidth
.ml-flexy__col--1of128.3333%
.ml-flexy__col--1of616.6666%
.ml-flexy__col--1of425%
.ml-flexy__col--1of333.3333%
.ml-flexy__col--1of250%
.ml-flexy__col--2of366.6666%
.ml-flexy__col--3of475%
.ml-flexy__col--5of683.3333%
.ml-flexy__col--11of1291.66666%
.ml-flexy__col--initialwidth of the column content
.ml-flexy__col--fillfill the available width
.ml-flexy__col--full100%

Responsive modifiers

Apply widths to breakpoints using the @from-XX suffix to the widths modifiers.

The available breakpoints modifiers are:

ModifierBreakpointCorresponding device
ml-flexy__col--[size] (no modifier)From 0px and upMobile / All
ml-flexy__col--[size]@from-mm: From 680px and upFablet / Small tablet and up
ml-flexy__col--[size]@from-ll: From 1024px and upLandscape tablets, laptops
ml-flexy__col--[size]@from-xlxl: From 1280px and upLaptops (depending on settings)
ml-flexy__col--[size]@from-xxlxxl: From 1920px and upDesktop

Viewport: px
<div class="example">
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--gutter">
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of12 example__col">
<div class="example__item">
1of12
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of6 example__col">
<div class="example__item">
1of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of6 example__col">
<div class="example__item">
1of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of6 example__col">
<div class="example__item">
1of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of6 example__col">
<div class="example__item">
1of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of6 example__col">
<div class="example__item">
1of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of6 example__col">
<div class="example__item">
1of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of6 example__col">
<div class="example__item">
1of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--5of6 example__col">
<div class="example__item">
5of6
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of4 example__col">
<div class="example__item">
1of4
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of4 example__col">
<div class="example__item">
1of4
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of4 example__col">
<div class="example__item">
1of4
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of4 example__col">
<div class="example__item">
1of4
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of4 example__col">
<div class="example__item">
1of4
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--3of4 example__col">
<div class="example__item">
3of4
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of3 example__col">
<div class="example__item">
1of3
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of3 example__col">
<div class="example__item">
1of3
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of3 example__col">
<div class="example__item">
1of3
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of3 example__col">
<div class="example__item">
1of3
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--2of3 example__col">
<div class="example__item">
2of3
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of2 example__col">
<div class="example__item">
1of2
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of2 example__col">
<div class="example__item">
1of2
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--full example__col">
<div class="example__item">
full
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--initial example__col">
<div class="example__item">
initial
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--fill example__col">
<div class="example__item">
fill
</div>
</div>
</div>
</div>
</div>

Alignment

You can align columns in a ml-flexy using the ml-flexy--items-[xxx] modifiers.

Available modifiers are:

ModifierValueBehavior
default (no modifiers)align-items: flex-startTop alignment
ml-flexy--items-endalign-items: flex-endBottom alignment
ml-flexy--items-centeralign-items: centerVertically centered
ml-flexy--items-startalign-items: flex-startTop alignment
ml-flexy--items-stretchalign-items: stretchAll columns use the same height

Viewport: px
<div class="example">
<span class="title">default :</span>
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--gutter">
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
<br />
A
<br />
<br />
<br />
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
B
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
C
<br />
<br />
</div>
</div>
</div>
</div>
<span class="title">ml-flexy--items-end : </span>
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--items-end ml-flexy--gutter">
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
<br />
A
<br />
<br />
<br />
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
B
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
C
<br />
<br />
</div>
</div>
</div>
</div>
<span class="title">ml-flexy--items-center : </span>
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--items-center ml-flexy--gutter">
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
<br />
A
<br />
<br />
<br />
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
B
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
C
<br />
<br />
</div>
</div>
</div>
</div>
<span class="title">ml-flexy--items-stretch : </span>
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--items-stretch ml-flexy--gutter">
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
<br />
A
<br />
<br />
<br />
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
B
</div>
</div>
<div class="ml-flexy__col example__col">
<div class="example__item">
<br />
C
<br />
<br />
</div>
</div>
</div>
</div>
</div>

Pushing a column to the left

You can push a column using the ml-flexy__col--push-[XofY] modifiers.

...
<div
class="
ml-flexy__col
ml-flexy__col--1of3
ml-flexy__col--push-1of3"
>
<!-- column content -->
</div>
...

All columns widths (numerical) are available as push values from 1of12, 1of6, 1of4 ... to 11of12.

Viewport: px
<div class="example">
<p>to create empty spaces between columns</p>
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--gutter">
<div
class="
ml-flexy__col
ml-flexy__col--1of6
example__col"
>
<div class="example__item">
1 of 6
</div>
</div>
<div
class="
ml-flexy__col
ml-flexy__col--push-1of12
ml-flexy__col--fill
example__col"
>
<div class="example__item">
fill / push 1 of 12
</div>
</div>
</div>
</div>
<p>for centering</p>
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--gutter">
<div
class="
ml-flexy__col
ml-flexy__col--2of3
ml-flexy__col--push-1of6
example__col"
>
<div class="example__item">
2 of 3 / push 1 of 6
</div>
</div>
</div>
</div>
</div>

Responsive push modifiers

Apply widths to breakpoints using the @from-XX suffix to the width modifiers.

The available breakpoints modifiers are:

ModifierBreakpointCorresponding device
ml-flexy__col--push-[size] (no modifier)From 0px and upMobile / All
ml-flexy__col--push-[size]@from-mm: From 680px and upFablet / Small tablet and up
ml-flexy__col--push-[size]@from-ll: From 1024px and upLandscape tablets, laptops
ml-flexy__col--push-[size]@from-xlxl: From 1280px and upLaptops (depending on settings)
ml-flexy__col--push-[size]@from-xxlxxl: From 1920px and upDesktop

Reset pushed modifiers

For a specific a breakpoint you can reset the pushed column using mc-flexy__col--push--reset@from-XX.

...
<div
class="
ml-flexy__col
ml-flexy__col--1of12
ml-flexy__col--push-1of12@from-l
ml-flexy__col--push-reset@from-xl
"
>
<!-- column content -->
</div>
...

Nesting flexy grids

You can either nest flexy grids by creating a new .ml-flexy grid inside a column, or by directly applying a .ml-flexy class on a .ml-flexy__column element.

Viewport: px
<div class="example">
<div class="ml-container example__container">
<main class="ml-flexy ml-flexy--gutter">
<aside class="ml-flexy__col ml-flexy__col--1of3">
<div class="example__item">
parent flexy - col 1of3
</div>
</aside>
<article class="ml-flexy__col ml-flexy ml-flexy--gutter">
<!-- netsed grid -->
<header class="ml-flexy__col ml-flexy__col--full">
<div class="example__item">
nested flexy - col full
</div>
</header>
<section class="ml-flexy__col ml-flexy__col--1of2">
<div class="example__item">
nested flexy - col 1of2
</div>
</section>
<section class="ml-flexy__col ml-flexy__col--1of2">
<div class="example__item">
nested flexy - col 1of2
</div>
</section>
<footer class="ml-flexy__col ml-flexy__col--full">
<div class="example__item">
nested flexy - col full
</div>
</footer>
</article>
</main>
</div>
</div>

Columns order

Use the ml-flexy__col--last and ml-flexy__col--first modifier to reorder columns.

Viewport: px
<div class="example">
<div class="ml-container example__container">
<div class="ml-flexy ml-flexy--gutter">
<div class="ml-flexy__col ml-flexy__col--1of3 ml-flexy__col--last">
<div class="example__item mu-mb-100 mu-mt-100">
A - order last
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of3">
<div class="example__item mu-mb-100 mu-mt-100">
B
</div>
</div>
<div class="ml-flexy__col ml-flexy__col--1of3 ml-flexy__col--first">
<div class="example__item mu-mb-100 mu-mt-100">
C - order first
</div>
</div>
</div>
</div>
</div>

Use flexy to center vertically and horizontally

Use the ml-flexy--space-around and the ml-flexy--items-center modifier on a ml-flexy element to center vertically and horizontally elements.

Viewport: px
<div class="ml-flexy ml-flexy--space-around ml-flexy--items-center example">
<div class="example__item">
Hello<br />
i'm centered
</div>
</div>