Palette — Layout

Grid

Our grid is a system of arranging content containers visually on the page. It consists of 12 columns that can be combined to organize your layout. With this system we can achieve quite complex layouts, but for the sake of simplicity and to avoid confusion this styleguide will only document the most common usage.

Basic usage:
Wrap your grid elements in a container with the class .row, and then give each grid element within a corresponding width class between .col-1 and .col-12. Say you want two equally sized elements, you’ll make a .row container and two .col-6 elements inside.

You’ll likely want your grid elements to adjust to the size of the browser. The easiest and most common way to achieve this is to let the grid elements stack vertically on smaller sizes. You can easily do this by replacing .col-1 to .col-12 with .col-md-1 to .col-md-12. This will make all grid elements fill the entire width on all browser widths below 720 pixels.

If for some reason you need to push the grid element from the edge, you’ll use the classes .offset[-md]-1 to .offset[-md]-12, same principle as the .col-[...] classes. See example for demonstration.

Consult a front-end person if you need more advanced layouts.

Example
.row
.col-md-4
.col-md-4
.col-md-4
.col-md-8
.col-md-4
.col-md-9.offset-md-3

Once more, without the responsive classes:

.row
.col-4
.col-4
.col-4
.col-8
.col-4
.col-9.offset-3

                    <!-- Responsive -->
                    <div class="row">
                        <div class="col-md-4">.col-md-4</div>
                        <div class="col-md-4">.col-md-4</div>
                        <div class="col-md-4">.col-md-4</div>
                        <div class="col-md-8">.col-md-8</div>
                        <div class="col-md-4">.col-md-4</div>
                        <div class="col-md-9 offset-md-3">.col-md-9.offset-md-3</div>
                    </div>
                    <!-- Not responsive -->
                    <div class="row">
                        <div class="col-4">.col-4</div>
                        <div class="col-4">.col-4</div>
                        <div class="col-4">.col-4</div>
                        <div class="col-8">.col-8</div>
                        <div class="col-4">.col-4</div>
                        <div class="col-9 offset-3">.col-9.offset-3</div>
                    </div>
                

Margin and padding

Margin is the spacing outside of an element, and padding is the spacing inside of an element. Think of a bordered box. If you need distance between the box and other boxes, you'll use margin. If you need distance between the border and what's inside the box, you'll use padding.

To use our margin and padding classes, you need to follow a formula to pick the appropriate class name. First you decide if you need a margin (m) or a padding (p), then we choose which sides you want to apply the spacing on, all sides (no extra variable), top (t), left (l), right (r), bottom (b), top and bottom (y) or left and right (x). The third variable you have to decide is how much spacing you need from 0 (no space) to 5 (a lot of space). Typically you'll want to use 2 for appropriate margin between elements and for padding inside of content boxes, but this is up to you. Try and see what works best.

So to get the spacing class you want, you'll follow this recipe: .{m/p}{sides(optional)}-{size}. If you need a "normal" sized bottom margin, you'll use the class .mb-2, and if you need just a little bit of padding on all sides, you'll use the class .p-1.

Example
  • .p-2: Padding / all sides / size 2
  • .m-2: Margin / all sides / size 2
  • .pt-4: Padding / top / size 4
  • .px-1: Padding / left and right / size 1
  • .mx-2: Margin / left and right / size 2

The dark background is the container, where you can see the margins, the light background visualizes the padding, and the white background is the contents of the boxes. The top box has even margin and padding on all sides, and the bottom box has matching left and right margin, and no top and bottom margin. Inside it has a very narrow left and right padding, and quite big top padding.

Display properties

Use .d-block, .d-inline, or .d-inline-block to simply set an element’s display property to block, inline, or inline-block (respectively).

Example

Inline

Inline


                    <h3 class="d-inline bg-success">Inline</h3>
                    <h3 class="d-inline bg-success">Inline</h3>
                
Block

                    <span class="d-block bg-primary">Block</span>
                

inline-block

Content

inline-block

Content


                    <div class="d-inline-block bg-warning">
                        <h3>inline-block</h3>
                        <p>Content</p>
                    </div>
                    <div class="d-inline-block bg-warning">
                        <h3>inline-block</h3>
                        <p>Content</p>
                    </div>
                

Responsive visibility

For faster mobile-friendly development, use these utility classes for showing and hiding content by device via media query. Try to use these on a limited basis and avoid creating entirely different versions of the same site. Instead, use them to complement each device’s presentation.

Extra small devices
Portrait phones (<544px)
Small devices
Landscape phones (≥544px - <768px)
Medium devices
Tablets (≥768px - <992px)
Large devices
Desktops (≥992px - <1200px)
Extra large devices
Desktops (≥1200px)
.hidden-xs-down Visible Visible Visible Visible
.hidden-sm-down Visible Visible Visible
.hidden-md-down Visible Visible
.hidden-lg-down Visible
.hidden-xl-down
.hidden-xs-up
.hidden-sm-up Visible
.hidden-md-up Visible Visible
.hidden-lg-up Visible Visible Visible
.hidden-xl-up Visible Visible Visible Visible