Grid

components/ui/_grid.scss

A simple and cascadable grid that is based on CSS Flexbox that supports multiple HTML tags.

In all the following examples on this page:

  • Flexbox items have red border
  • Fexbox containers have double solid light gray border

Legend:

Items have red border

Containers have double solid light gray border

  • I am a li into an ul
  • Items have red border
  • Containers have double solid light gray border

I am a span into a p Items have red border Containers have double solid light gray border

I am a span into an a Items have red border Containers have double solid light gray border
I am a article into a section
Items have red border
Containers have double solid light gray border

Multiple grids

Hello!
Items have green border
Flexbox grids have dotted gray border
Another my-grid
Another flexbox

Cascading

You can include as mush as grids as you wish into a single item.

Hello!
Items have green border
Below another my-grid:
Cascading
is
easy:
Another cascading
example

Auto grow

Modifier class name for items .mod-grow allows to fill the blank space.

This is an example
of
mod-grow
This is an example
of
mod-grow
This is an example
of
mod-grow

Responsive wrapping

By default grid items automatically wrap when there is no enough space. For each screen size or globally, it is possible to force items to stay into their axis with .mod-nowrap[-screenSizeName] modifier.

Grid without mod-nowrap
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Row with mod-nowrap
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
No wrap only on sm screen size
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Inline

By default flexbox container behaves like a block, spreading over all the available width. It is possible to switch to an inline mode by using modifier .mod-inline

Example of a grid with mod-nowrap:

Default grid
Container uses all available width.
Item
Inline grid
Container width based on content.
Item

Horizontal alignment

  • .mod-left Items are pushed towards the start of the container’s main axis.
  • .mod-center Items are centered along the container’s main axis.
  • .mod-right Items are pushed towards the end of the container’s main axis.
  • .mod-space-between The remaining space is distributed between the items.
  • .mod-space-evenly Distribute items evenly. Items have equal space around them.
  • .mod-space-around Items are evenly distributed with equal space around them.
Default container and its
flex
items
mod-center container and its
flex
items
mode-right container and its
flex
items
mod-space-between container and its
flex
items
mod-space-evenly container and its
flex
items
mod-space-around container and its
flex
items
/* DEMO ONLY */ .my-grid+.my-grid { margin-top: 2em;}

Vertical alignment

  • .mod-top Items are aligned at the start of the cross axis.
  • .mod-middle Items are centered vertically along the container’s cross axis.
  • .mod-bottom Items are aligned at the end of the cross axis.
  • .mod-baseline Items are aligned at the baseline of the cross axis.
1. Flex item
Flex items height is equal to the tallest item.
Flex item
2. Flex item
Flex item vertically aligned on top.
Flex item
3. Flex item
Flex item vertically aligned on middle.
Flex item
4. Flex item
Flex item vertically aligned on bottom.
Flex item

5. h1 flex item

Vertically align items on first line

This example uses HTML5 tags.

Alignments combinations

Here follows examples of combinations between main and cross axis alignment.

1. mod-center mod-middle
center
both axis
2. mod-middle
Horizontally left
Vertically centered
3. mod-right mod-middle
Horizontally right
Vertically centered
4. mod-bottom
Horizontally left
Vertically bottom
5. mod-right mod-bottom
Horizontally right
Vertically bottom
6. mod-right mod-top
Horizontally right
Vertically top
.my-grid { height: 50vh; //for demo only }

Column

By default, flex flow is set to rows. It can be set to columns with the modifier .mod-column

1. A standard grid
flow
is horizontal
2. mod-column
flow
modified by column
3. mod-column mod-top
flow
modified by column + aligned on left
4. mod-column mod-center
flow
modified by column + aligned center
5. mod-column mod-right
flow
modified by column + aligned on right
6. mod-column mod-center mod-middle
flow
modified by column + aligned middle center
7. mod-column mod-right mod-bottom
flow
modified by column + aligned bottom right
[data-demo-only] {height:50vh;}

Responsive reverse

Rows and columns flows can be reversed responsively with modifier .mod-reverse[-screenName]

A grid
flow
reversed
A grid
flow
reversed only on sm screen size
A grid
flow
reversed
A grid
flow
reversed only on sm screen size

Responsive order

It is possible to set a specific flex item at first place globally or on specified screen size with the responsive modifier .mod-order--1[-screenName]

Sets order:-1 to the specified grid item.

1
2
3
4. Last but always first
1
2
3
4. Last but always first on sm screen size

Relative width

Modifier class name format .mod-w-[number]

Sets the relative width of items in percentage with 1/12 steps.

  • .mod-w-12 Sets the width of the item to 100% (12/12).
  • .mod-w-11 Sets the width of the item to 91.6666% (11/12).
  • .mod-w-10 Sets the width of the item to 83.3333% (5/6).
  • .mod-w-9 Sets the width of the item to 75% (3/4).
  • .mod-w-8 Sets the width of the item to 66.6666% (2/3).
  • .mod-w-7 Sets the width of the item to 58.3333% (7/12).
  • .mod-w-6 Sets the width of the item to 50% (1/2).
  • .mod-w-5 Sets the width of the item to 41.6666% (5/12).
  • .mod-w-4 Sets the width of the item to 33.3333% (1/3).
  • .mod-w-3 Sets the width of the item to 25% (1/4).
  • .mod-w-2 Sets the width of the item to 16.6666% (1/6).
  • .mod-w-1 Sets the width of the item to 8.3333% (1/12).
  • .mod-w-0 Sets the width of the item to 0% (0/12).
mod-w-12
mod-w-11
mod-w-1
mod-w-10
mod-w-2
mod-w-9
mod-w-3
mod-w-8
mod-w-4
mod-w-7
mod-w-5
mod-w-6
mod-w-6
mod-w-6
No width specified
No width specified
mod-w-6

Responsive width

Same usage as global width but modifiers contain screen size name .mod-w-[number]-[screenSizeName]. Thus, the more amount of screen sizes you have, the more you get responsive width modifiers.

Current screen sizes settings are:

$ds-screen-sizes: (
    sm: 768,
    md: 1024,
    lg: 1440,
    xl: infinite
);

Here are some of the responsive classes you get:

Responsive fixed width

Modifier class name format .mod-fw-[fixedWidthName].

Assign fixed width according to grid settings $grid-items-fixed-widths. Fixed widths override relative widths.

Always fixed widths:

mod-fw-mini
mod-fw-medium

Fixed widths on specific screen size:

mod-fw-mini-sm
mod-fw-medium-sm

Relative width + responsive fixed widths:

Always 50% width but "mini" fixed width on "sm" screen sizes
Always 100% width but "medium" fixed width on "sm" screen sizes

Max widths

Grid allows custom max width for items through the modifier .mod-mw-[maxWidthName].

50% width
50% width but max width 200px
100% width
100% width but max width 300px

Gutter

Gutter modifer .mod-gutter simply applies a spacing around the items based on SASS variable $grid-gutter

A gutter row
mod-w-9
mod-w-3
mod-w-8
mod-w-4
mod-w-7
mod-w-5
mod-w-6
mod-w-6
A non gutter row
mod-w-9
mod-w-3
mod-w-8
mod-w-4
mod-w-7
mod-w-5
mod-w-6
mod-w-6
Cascading gutter row into a non gutter row
mod-w-9
mod-w-3
mod-w-8
mod-w-4
mod-w-7
mod-w-5
mod-w-6
mod-w-6

Responsive gutter

$grid-gutter-default is the default margin for gutter.

It is possible to override the default gutter for each screen size:

$grid-gutter-responsive: (
    sm: 5px //5px gutter for *sm* screen size.
);

Responsive gutter shadow

$grid-gutter-box-shadow-default is the default shadow applied on every item.

It is possible to override the default gutter shadow for each screen size:

$grid-gutter-box-shadow-responsive: (
    sm: my-shadow(1-soft) // Shadow called "1-soft" for "sm" screen size
);

No gutter shadow

It is possible to disable shadow on gutter items with modifier .mod-noshadow on flex parent. It is also possible to add shadow on specific gutter items even if noshadow modifier is set on its parent:

A
simple
gutter
grid
A
simple
gutter
grid

Aspect ratio

It is possible to force items into a custom aspect ratio with the modifier .mod-ar-[aspectRatioName]

On container

16% width with aspect ratio square
33% width with aspect ratio square
50% width with aspect ratio disabled
16% width with aspect ratio widescreen
33% width with aspect ratio widescreen
50% width with aspect ratio disabled
16% width with aspect ratio scope
33% width with aspect ratio scope
50% width with aspect ratio disabled

On specific items, you must add a vertical alignment modifier on container to get proper aspect ratio.

16% width with aspect ratio square
33% width with aspect ratio widescreen
50% width with aspect ratio scope
16% width
33% width
50% width