Layout (grid and flex)

Grid vs Flexbox

Note: You can even combine these layout models. Note that you can use a Flexbox container inside a CSS Grid container but you cannot implement it vice-versa. See image below for a visual perspective.


For details, refer to Beginner’s Guide To CSS Grid And Flexbox

Styleguide grid: Grid

Styleguide flexbox: Flexbox

Grid

CSS Grid Layout is the most powerful layout system available in CSS. It is a 2-dimensional system, meaning it can handle both columns and rows, unlike flexbox which is largely a 1-dimensional system. You work with Grid Layout by applying CSS rules both to a parent element (which becomes the Grid Container) and to that element's children (which become Grid Items). For more details, refer to CSS Grid

Currently, we have four predefined basic grid classes that are widely used in the new design. For details, refer to the mixins/grid.css file.

Classes use grid-template-columns: repeat(auto-fill, minmax(30rem, 1fr)) approach which means that the website displays the maximum number of columns that has some predefined width. That means that the number of columns is elastic and responsive.

We also have two additional grid classes that determines the number of columns without definiting the minimum or maximum width.

Additionally, if you need to have smaller spacing between columns and rows you can use the elastic-grid--horizontal-condensed or elastic-grid--horizontal-gaps--small classes.

Code is similar in every case, the grid class should be placed directly in the container div that should contain elements (ideally div's) which form columns.


Grid examples

Elastic grid horizontal 12

Industry guide


Reset fields

Volunteers



<div class="elastic-grid--horizontal-12">
  <div>Column 1</div>
  <div>Column 2</div>
  <div>Column 3</div>
  <div>Column 4</div>
  <div>Column 5</div>
</div>

Elastic grid horizontal 15

Industry guide

VP status: Not submitted

Reset fields

Volunteers for festival of lights

VP status: Not submitted


<div class="elastic-grid--horizontal-15">
  <div>Column 1</div>
  <div>Column 2</div>
  <div>Column 3</div>
  <div>Column 4</div>
  <div>Column 5</div>
</div>

Elastic grid horizontal 20

Industry guide

VP status: Not submitted

Reset fields

Volunteers for festival of lights

VP status: Not submitted


<div class="elastic-grid--horizontal-20">
  <div>Column 1</div>
  <div>Column 2</div>
  <div>Column 3</div>
</div>

Elastic grid horizontal 30

Industry guide

VP status: Not submitted

Reset fields

Volunteers for festival of lights

VP status: Not submitted


<div class="elastic-grid--horizontal-30">
  <div>Column 1</div>
  <div>Column 2</div>
</div>

Elastic grid vertical


<div class="elastic-grid--vertical">
  <div>Column 1</div>
  <div>Column 2</div>
</div>

Flexbox

The main idea behind the flex layout is to give the container the ability to alter its items' width/height (and order) to best fill the available space (mostly to accommodate to all kind of display devices and screen sizes). A flex container expands items to fill available free space, or shrinks them to prevent overflow. For more details, refer to CSS Flexbox or Flexbox Properties Demonstration.

We have a lot of predefined classes for flexbox properties that can be used directly in the HTML code. To see the full list of classes, go to base/utilities.css.