Gridlock

April 4, 2015 · View on GitHub

Development of this plugin has ended. Please upgrade to the new Formstone.


Built with Grunt

Gridlock

A responsive CSS grid system. Part of the Formstone Library.

Bower Support

bower install Gridlock


Usage

Gridlock works by nesting 'cells' within 'rows'. Cells are defined by classes that set widths at specific breakpoints. The breakpoints correspond to general screen sizes. By default, Gridlock renders 3 columns on mobile, 6 columns on tablet and 12 columns on desktop.

Markup

A basic example may look something like:

<body class="gridlock">
	<div class="row">
		<div class="mobile-3 tablet-2 desktop-4">...</div>
		<div class="mobile-3 tablet-2 desktop-4">...</div>
		<div class="mobile-3 tablet-2 desktop-4">...</div>
	</div>
</body>

This will create 3 cells that each span 3 columns on mobile, 2 columns on tablet and 4 columns on desktop screen sizes. You can think of the nested structure like a directory tree:

gridlock
├─ row
|  ├─ cell
|  |─ cell
|  |  └─ row
|  |     ├─ cell
|  |     └─ cell
|  └─ cell
└─ row
   ├─ cell
   └─ cell

Box-Sizing

Gridlock relies on border-box and includes a global box-sizing reset:

*, *:before, *:after {
	-webkit-box-sizing: border-box;
	   -moz-box-sizing: border-box;
	        box-sizing: border-box;
}

This will effect every element on the page and can have unexpected results. In the long run it will help speed development by modifying how padding and borders effect the box model calculations. Learn more about border-box.

Row Widths and Columns Counts

NameScreen SizeRow WidthColumn Count
minsmaller than 500px300px3
mobilesmaller than 740px480px3
tablet740px to 960px720px6
desktop960px to 1220px960px12
maxlarger than 1220px1200px12

Defining Cells

ClassDescription
min-Xonly min size
mobile-Xboth mobile and min sizes
tablet-Xtablet size
desktop-Xboth desktop and max sizes
max-Xonly max size
all-Xall sizes

Cells are defined by the target screen size and column count, relative to it's screen size. For example mobile-2 will produce a cell spanning 2 of the 3 available columns in the mobile screen size range. Cell classes should be stacked to specify column spans across all screen sizes:

<div class="mobile-3 tablet-6 desktop-12">...</div>

The max-X and min-X classes give you an added level of control when targeting the desktop and mobile sizes. For example, you may need a cell to span 2 columns at the larger mobile size, but span the full width at the smallest mobile size:

<div class="min-3 mobile-2 ...">...</div>

The all-X classes give you the ability to create a cell that spans the specified width on all screen sizes (only works with fraction cells):

<div class="all-full ...">...</div>

Fraction Cells

You can also use the fraction classes in place of specific column counts:

ClassDescription
X-fullentire row width
X-half1/2 row width
X-third1/3 row width
X-fourth1/4 row width

Hidden Cells

You can hide cells at specific screen sizes:

ClassDescription
min-hideHide on min
mobile-hideHide on mobile
tablet-hideHide on tablet
desktop-hideHide on desktop
max-hideHide on max

Helper Classes

Helper classes can be added to cells to modify their default behavior in predictable ways.

ClassDescription
paddedSwaps cell margin for padding. Allows backgrounds to touch while maintaining gutters.
containedRemoves cell margin. Allows backgrounds to touch by removing gutters.
centeredCenters cell. Useful for centering odd column count cells.

LESS Configuration

Gridlock can also be configured and rebuilt using Grunt. Simply edit the variables found in /src/fs.gridlock-config.less before running the default grunt process.

VariableDefaultDescription
Structure
@class-containergridlockContainer class
@class-rowrowRow class
@class-containedcontainedContained helper class
@class-paddedpaddedPadded helper class
@class-centeredcenteredCentered helper class
Cells
@class-allallAll cell class
@class-minminMin cell class
@class-mobilemobileMobile cell class
@class-tablettabletTablet cell class
@class-desktopdesktopDesktop cell class
@class-maxmaxMax cell class
Columns
@columns-mobile3Mobile column count
@columns-tablet6Tablet column count
@columns-desktop12Desktop column count
Widths
@width-min300pxMin row width
@width-mobile480pxMobile row width
@width-tablet720pxTablet row width
@width-desktop960pxDesktop row width
@width-max1200pxMax row width
Breakpoints
@width-break-min320pxMin break width
@width-break-mobile500pxMobile break width
@width-break-tablet740pxTablet break width
@width-break-desktop980pxDesktop break width
@width-break-max1220pxMax break width
Gutters
@gutter1.0416666666666667%;Gutter width