postcss-grid
A semantic grid system for PostCSS
Installation
npm install postcss-grid
Usage
var fs = ;var postcss = ;var grid = ; var css = fs; var options = columns: 12 // the number of columns in the grid maxWidth: 960 // the maximum width of the grid (in px) gutter: 20 // the width of the gutter (in px) legacy: false // fixes the double-margin bug in older browsers. Defaults to false; var output = css;
Columns
Columns are created by using the grid-column
declaration and passing a /
-delimited value. This value contains the number of columns the element should span, separated by the total number of columns in the element's container.
Example:
Turns into:
You can also use it in conjunction with the !last
declaration to make sure that the last element of the row doesn't allocate a gutter, pushing itself to the next row.
Example:
Turns into:
Offsetting elements
Elements can be offset to the left and the right by using grid-pull
and grid-push
.
Example:
Turns into:
Width and gutter values
The width and gutter values can be retrieved by calling grid-width(...)
and grid-gutter(...)
from a declaration.
Example:
Turns into: