• Stars
    star
    1,491
  • Rank 31,502 (Top 0.7 %)
  • Language
    CSS
  • License
    Other
  • Created almost 12 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple, fluid, nestable, flexible, Sass-based, responsive grid system.

csswizardry-grids

Simple, fluid, nestable, flexible, Sass-based, responsive grid system.

  • Fully responsive
  • Mobile first
  • Infinitely nestable
  • Reversible/reorderable
  • With/without gutters
  • Endless possible combinations
  • Simple to understand, human-friendly classes
  • Option to keep classes out of your HTML
  • Robust
  • Simple
  • No .clear or .last classes
  • It just works

Please see Responsive grid systems; a solution? for a comprehensive overview of the principles of the grid system.

Demo

Setup

Simply fill in/adjust the relevant variables.

  • $responsive is used to turn csswizardry-grids’ responsive features on and off. csswizardry-grids is designed primarily for responsive builds but can also be used on non-responsive projects just as easily. Setting this to false will simply prevent Sass generating your palm etc modifiers.
  • $gutter controls how much space there is between columns.
  • $mobile-first controls whether you would like unclassed grid items to initially adopt `width:100%;. This means that you won’t need to add a class to force a grid item to take up the full width of its container.
  • $use-silent-classes tells csswizardry-grids whether to go ahead and compile solid, traditional classes (e.g. .one-whole) or to create Sass ‘silent’ classes which only compile to CSS once explictly called.
  • $lap-start and $desk-start tell csswizardry-grids when to fire particular media queries to service those particular sizes. Note that csswizardry-grids works out the ends of any other breakpoints by using these numbers.

Usage

csswizardry-grids is incredibly simple to implement, its classes are all human-readable and follow the same pattern.

Patterns

csswizardry-grids’ classes are based on a modified BEM syntax.

  • .grid is a Block
  • .grid__item is an Element
  • .grid--rev is a Modifier

Classes include your breakpoint namespaces (e.g. .palm--one-half, .desk--two-thirds and so on); your push and pull classes (.push--one-third, .pull--desk--one-quarter and so on); your regular classes (.one-tenth, .three-quarters etc).

Knowing these patterns will allow you to create hundreds of different combinations. A few examples:

/**
 * Sets an item to be one half across all breakpoints.
 */
.one-half{}

/**
 * Pushes an item one third of the way to the right across all breakpoints.
 */
.push--one-third{}

/**
 * Sets an item to be ten twelfths wide only at the desk breakpoint.
 */
.desk--ten-twelthfs{}

/**
 * Pulls an item one half of the way to the left only at the palm breakpoint.
 */
.pull--palm--one-half{}

Classes in markup

If you are using traditional classes then an example, basic usage might look like this:

<div class="grid">

    <div class="grid__item  lap--one-half  desk--two-thirds">
        ...
    </div><!--

 --><div class="grid__item  lap--one-half  desk--one-third">
        ...
    </div>

</div>

It’s as simple as that!


Note the empty HTML comments. These are to remove whitespace caused by using inline-block. Prior to v1.1 this was tackled by using some [letter|word]-spacing trickery, however Chrome 25 introduced a change which meant this method now broke csswizardry-grids.

If you’d rather not use HTML comments to remove the whitespace then you can set the $use-markup-fix variable to false; this invokes a CSS hack that cannot be guaranteed. Always take care to check things over if using this method.

If you need to use csswizardry-grids with a CMS, or data coming out of a loop, you will need to format your template something a little like this:

<div class="grid">
<!--
<?php
    $items = array('foo', 'bar', 'baz');

    foreach ($items as $item) {
?>

--><div class="grid__item  one-third">
    <?= $item ?>
</div><!--

<?php
    }
?>
-->
</div>

Note the opening and closing comments before and after the loop, and the corresponding opening and closing comments facing outward from the .grid__item element. Try pasting the above into the codepad code runner: items from a loop without the need for a counter :)


Sass’ silent classes

If you are using silent classes ($use-silent-classes: true;) then your HTML might look like this:

<div class="page">

    <div class="content">
        ...
    </div><!--

 --><div class="sub-content">
        ...
    </div>

</div>

…and your Sass, something like this:

.page{
    @extend %grid;
}

    .content,
    .sub-content{
        @extend %grid__item;
        @extend %one-whole;
        @extend %lap--one-half;
    }

    .content{
        @extend %desk--two-thirds;
    }

    .sub-content{
        @extend %desk--one-third;
    }

Reversed grids (.grid--rev{})

csswizardry-grids has the option to reverse a set of grids; this means that the order you write your source and the order it renders are total opposites, for example:

<div class="grid  grid--rev">

    <div class="main-content  grid__item  two-thirds">
        I appear first in the markup, but render second in the page.
    </div><!--

 --><div class="sub-content  grid__item  one-third">
        I appear second in the markup, but render first in the page.
    </div>

</div>

This is handy if you want to lay out your page a certain way visually but it would be advantageous to order the source differently, for example to aid accessibility (getting a screenreader to read more important content first).

Gutterless grids (.grid--full{})

It may be desirable at times to have no gutter between your grid items; with csswizardry-grids this is as simple as:

<div class="grid  grid--full">

    <div class="grid__item  one-half">
        Look, ma! No gutter!
    </div><!--

 --><div class="grid__item  one-half">
        Look, ma! No gutter!
    </div>

</div>

Right-aligned grids (.grid--right{})

Keep grids in their correct order, but have them flush right instead of left:

<div class="grid  grid--right">

    <div class="grid__item  one-quarter">
        I render first but start in the middle of the page.
    </div><!--

 --><div class="grid__item  one-quarter">
        I render second and appear at the very right edge of the page.
    </div>

</div>

Centred grids (.grid--center{})

You can centrally align your grids by simply using the .grid--center modifier:

<div class="grid  grid--center">

    <div class="grid__item  one-half">
        I’m in the middle!
    </div>

</div>

Vertically aligned grids (.grid--[middle|bottom]{})

You can vertically align your grids to each other by simply using the .grid--[middle|bottom] modifiers:

<div class="grid  grid--middle">

    <div class="grid__item  one-half">
        I’m in the middle!
    </div>

    <div class="grid__item  one-half">
        I’m in the middle!
    </div>

</div>

Different sized grids (.grid--[narrow|wide]{})

You can quickly alter the gutter size of your grids to half (.grid--narrow) or double (.grid--wide) by using the relevant modifiers.

<div class="grid  grid--narrow">

    <div class="grid__item  one-half">
        I’m a narrow-guttered grid.
    </div>

    <div class="grid__item  one-half">
        I’m a narrow-guttered grid.
    </div>

</div>

Help and questions

If you have any trouble setting csswizardry-grids up, or would like some help using and implementing it (or any questions about how it works) then please feel free to fire me a tweet or open an issue.

csswizardry-grids’ Sass can look a little daunting, but it’s doing quite a lot of work behind the scenes to make it as simple as possible when it comes to implementation.

More Repositories

1

inuit.css

Powerful, scalable, Sass-based, BEM, OOCSS framework.
CSS
3,838
star
2

CSS-Guidelines

High-level guidelines for writing manageable, maintainable CSS
3,653
star
3

ct

Let’s take a look inside your <head>…
CSS
1,848
star
4

typecsset

A small Sass library for setting type on the web.
CSS
713
star
5

csswizardry.github.com

My site.
HTML
463
star
6

nudge

Warn developers about improper selector usage
CSS
225
star
7

beautons

A beautifully simple button toolkit
CSS
211
star
8

csscv

A simple, opinionated stylesheet for formatting semantic HTML to look like a CSS file.
CSS
205
star
9

vanilla

My personal starting point for new builds.
HTML
184
star
10

discovr

CSS Architecture workshop files
CSS
172
star
11

frcss

CSS
107
star
12

dotfiles

Starting small… my dotfiles for a few things.
Vim Script
102
star
13

inuit.css-web-template

Web template for housing the inuit.css framework as submodule
CSS
88
star
14

ama

Ask me anything!
58
star
15

recipes

Collection of things I like cooking
42
star
16

pr.ofile.me

Digital, mobile business cards
40
star
17

hry.rbrts.me

Personal hub site.
Racket
20
star
18

build-along-1

The first CSS Wizardry build-along
17
star
19

css-architecture

Workshop materials
CSS
16
star
20

fluid-grids

PHP
15
star
21

extend-vs-mixin

CSS
13
star
22

work

Dedicated ‘work’ page for CSS Wizardry
HTML
12
star
23

fep

9
star
24

sampenrose.co.uk

Portfolio
6
star
25

demo-component

CSS
5
star
26

harry.is

HTML
3
star
27

gilliansibthorpe.com

HTML
2
star
28

questions-for-consultants-issues

Public issue tracker for my eBook, Questions for Consultants
2
star
29

test

1
star
30

wishlist

Because I’m greedy like that…
1
star
31

press

Bios and stuff…
1
star
32

toolkit-core

CSS
1
star
33

piccalilli-burger-menu-demo

HTML
1
star
34

markrabey.github.io

CSS
1
star
35

nightingale-demo

HTML
1
star
36

bower-demo

CSS
1
star