Introduction Modules Flavors Customization Github

mini.css

v2.0

Grid

The grid module provides you with a modern, responsive grid system based on the Flexible Layout Module (commonly known as flexbox). The structure of the grid is simple and logical, allowing you to quickly build your pages from scratch. Setting the layout for a page is easy and will behave the way you want them to on mobile devices and smaller screens.

All examples showcased refer to the mini-default flavor, some class names and styles might differ based on the flavor you're using.

Quick overview

Easy page layout is one of the main advantages of using a CSS toolkit over writing your own styles. The grid module utilizes the Flexbox Layout to provide you with a modern and responsive layout grid system for all your needs. Rules in the grid module help you create basic fluid containers for your grid and allow you to design layouts that work well on all screen sizes using a simple row and column structure. The grid system contains definitions for both fluid columns that resize according to their siblings and columns with preset sizes on different screen sizes, as well as rules that allow you to move certain columns to the first or last place on the grid's row on different devices, helping you present the page in a different layout without duplicating any content. All of the rules in the module are built around accessibility, so screen readers can easily read you pages.


Quick start

To use the grid module, simply include the link to the flavor you are using and start writing your HTML page as usual. One suggestion we will make is to add the following line inside your HTML page's <head> to utilize the viewport meta tag:


<meta name="viewport" content="width=device-width, initial-scale=1">

Basic layout


1
11
2
10
3
9
4
8
5
7
6
6
12
fluid
fluid

The grid system's basic layout is composed of three components, presented below in the order they should be added to the DOM tree:

  1. The grid's .container is the outermost shell for your grid. It is a fluid container that serves wrap the flexible grid system inside it.
  2. Inside the container, .rows are added to specify each row of the grid layout. Rows serve to provide you with a simple basis for your layout's columns.
  3. Finally, inside the rows, .col- elements are added for the columns. The columns are a little bit more complex than the container and rows, as they are what makes the layout respond to changes. There are two basic ways to define a column for your layout:
    • using .col-SCR_SZ to specify fluid columns, replacing SCR_SZ with one of the available screen size names (sm for smaller screens, md for medium-sized screens or lg for larger screens).
    • using .col-SCR_SZ-COL_WD to specify columns with fixed width, replacing SCR_SZ with one of the available screen size names and COL_WD with a number from 1 to 12 specifying the width of the column (1 meaning 1/12 of the width of the row and 12 meaning 100% of the width of the row).

Sample code

The sample code is a bit lengthy, so we hid it by default to make it easier for mobile device users to read this page. Click or tap on Show sample code below to see the code sample for this example. Also, the example presented showcases the grid system's syntax for smaller screens, but you can do the same thing for any screen size.


<div class="container">
  <div class="row">
    <div class="col-sm-1">
    </div>
    <div class="col-sm-11">
    </div>
  </div>
  <div class="row">
    <div class="col-sm-2">
    </div>
    <div class="col-sm-10">
    </div>
  </div>
  <div class="row">
    <div class="col-sm-3">
    </div>
    <div class="col-sm-9">
    </div>
  </div>
  <div class="row">
    <div class="col-sm-4">
    </div>
    <div class="col-sm-8">
    </div>
  </div>
  <div class="row">
    <div class="col-sm-5">
    </div>
    <div class="col-sm-7">
    </div>
  </div>
  <div class="row">
    <div class="col-sm-6">
    </div>
    <div class="col-sm-6">
    </div>
  </div>
  <div class="row">
    <div class="col-sm-12"> 
    </div>
  <div class="row">
    <div class="col-sm">
    </div>
    <div class="col-sm">
    </div>
  </div>
</div>

Notes

  • mini.css uses a mobile-first approach to the grid system. This means that specifying a layout for smaller device sizes will apply the same layout on medium and large screens, so you do not have to rewrite the same layout for all three screen sizes. However, if you want to change the layout on different screen sizes, check the section below.
  • The grid module is compatible with modern browsers, but does not display properly on older browsers.
  • The specific breakpoints for small, medium and large screen sizes are as follows:
    • small: less than 768px wide
    • medium: more than or equal to 768px wide but less than 1280px wide
    • large: 1280px wide or more

<div class="col-sm">
    <div class="container">
    </div>
</div>
<!-- or -->
<div class="col-sm">
    <div class="row">
    </div>
</div>

Do: A column can contain a container or a row inside it. The container can also be skipped if inside a column, so you only need to add a row.

<div class="col-sm">
    <div class="col-sm">
    </div>
</div>

Don't: Avoid using columns inside columns without a row wrapping them. Either make the outer column a row in itself or wrap the inside columns in a row.

<div class="col-sm row">
    <div class="col-sm-6">
    </div>
    <div class="col-sm-6">
    </div>
</div>

Do: A column can also be a row at the same time, if you want to include sub-columns inside it. You can make the same element both a column in its own row and a row for its containing columns. The same can be applied for the container. Containers can, however, be omitted, when already inside a grid.

<div class="row">
    <!-- content without columns -->
</div>

Don't: Avoid using rows with content inside that is not in columns. Prefer to use a single .col-sm to wrap the content inside these, otherwise there might be unexpected behavior.

 <div class="row">
    <div class="col-sm">
    <div>
    <div class="col-sm-4">
    </div>
 </div>
<!-- or -->
 <div class="row">
    <div class="col-sm-12">
    <div>
    <div class="col-sm-12">
    </div>
 </div>

Do: Mix fluid columns with fixed, if you like. Fluid columns will adapt to the size of the container left for them. You can also use columns with a total width of more than 12, meaning with a total width of over 100%. The remaining content will flow below the rest, allowing you to specify multiple blocks of content inside the same row if you need to.

<div class="container">
    <div class="row">
        <div class="col-sm">
        <div>
    </div>
    <p>Normal paragraph.</p>
</div>
<!-- or -->
<div class="row">
    <div class="col-sm">
    </div>
    <p>Normal paragraph.</p>
</div>

Don't: Avoid mixing rows and columns with normal content that is not wrapped in the respective level of the grid system. Always wrap content inside the proper containers (container, row or column) in your grid layout.

Screen-specific layouts

Small screen layout


Medium/Large screen layout


Sample code


Column offsets

Sample code


Column ordering

Sample code


Dos and Don'ts

DO: Col-sm-12 col-md, col-sm-12 col-md, DONT: row > col-sm-12 col-md / row > col-sm-12 col-md, DONT: Spec col-md but no col-sm!!

Sample code


If you want to learn more about mini.css's modules, go back to the modules page and choose another module to see its documentation.