Slides available at
http://snugug.github.io/responsive-grids
(link will be available again at the end)
Grids enforce proportion and constraint on your design
They provide order and structure to your information.
The best grid is specific to your content and your design, as it is an extension of both.
// We switch our box model to Border Box.
// From [Paul Irish](http://paulirish.com/2012/box-sizing-border-box-ftw/)
*, *:before, *:after {
box-sizing: border-box;
}
gem 'singularitygs', '~>1.4.0'
require 'singularitygs'
@import 'singularitygs';
@include add-grid(12);
@include add-gutter(1/3);
@include add-grid(12);
@include add-gutter(0.9375em);
@include add-gutter-style(split);
@include add-grid(12);
@include add-gutter(0);
@include add-grid(1 4 1);
@include add-gutter(1/6);
@include add-gutter-style(split)
// Compound function from [Singularity Extras](https://github.com/Team-Sass/Singularity-extras)
@include add-grid(compound(3, 4));
@include add-gutter(1);
// Ratio function from [Singularity Extras](https://github.com/Team-Sass/Singularity-extras)
@include add-grid(ratio(golden-ratio(), 4));
@include add-gutter(golden-ratio() * 1em);
@include add-gutter-style(split);
// Ratio spiral function from [Singularity Extras](https://github.com/Team-Sass/Singularity-extras)
@include add-grid(ratio-spiral(5));
@include add-gutter(1);
// Calc output style from [Singularity Extras](https://github.com/Team-Sass/Singularity-extras)
@include add-grid(320px 1 2);
@include add-gutter(1em);
@include sgs-change('output', 'calc');
Singularity is what is referred to as semantic grid system. This means that instead of grid classes being generated that you apply to your HTML, the grid is stored entirely within your CSS and applied directly to the element you want to use it on.
Yes, I know classes don't have semantic value.
<body>
<div class="main">Main Section</div>
<div class="first">First Section</div>
<div class="second">Second Section</div>
</body>
@include add-grid(1 4 1);
@include add-gutter(1/6);
.main {
@include grid-span(1, 2);
}
.first {
@include grid-span(1, 1);
}
.second {
@include grid-span(1, 3);
}
When nesting grids, if we want gutters of symmetric and asymmetric grids to line up, we want to snap our asymmetric grids
@include add-grid(snap(2 4 4 2, 1/3));
<body>
<div class="main">
<div class="one">One</div>
<div class="two">Two</div>
<div class="three">
<div class="a">Three A</div>
<div class="b">Three B</div>
<div class="c">Three C</div>
</div>
<div class="four">Four</div>
</div>
<div class="first">First Section</div>
<div class="second">Second Section</div>
</body>
@include layout(8, 1/3) {
.one {
@include grid-span(4, 5);
}
.two {
@include grid-span(2, 1);
}
.three {
@include grid-span(5, 3);
clear: both;
}
.four {
@include grid-span(2, 4);
clear: both;
}
}
@include layout(snap(1 2 2, 1/3), 1/3) {
.a {
@include grid-span(1, 3);
}
.b {
@include grid-span(1, 1);
}
.c {
@include grid-span(1, 2);
}
}
gem 'breakpoint', '~>2.5.0'
require 'breakpoint'
@import 'breakpoint';
With Breakpoint, your basic min-width
media queries get reduced to a single value
$breakpoint-to-ems: true;
$nav-inline: 532px;
nav {
background: #c0ffee;
@include breakpoint($nav-inline) {
background: #decaff;
}
}
nav {
background: #c0ffee;
}
@media (min-width: 33.25em) {
nav {
background: #decaff;
}
}
Providing fallbacks for when media queries aren't available is easy too
$breakpoint-no-query-fallbacks: true;
$breakpoint-to-ems: true;
$nav-inline: 532px, 'no-query' '.no-mq';
nav {
background: #c0ffee
@include breakpoint($nav-inline) {
background: #decaff
}
}
nav {
background: #c0ffee;
}
@media (min-width: 33.25em) {
nav {
background: #decaff;
}
}
.no-mq nav {
background: #decaff;
}
You can call each add-* mixin multiple times and specify a min-width
breakpoint in which to change that item's global context
$bkpt-1: 600px;
$bkpt-2: 1050px;
@include add-grid(.25 8 .25);
@include add-grid(1.618 2.61792 at $bkpt-1);
@include add-grid(2 8 2 at $bkpt-2);
@include add-gutter(.25);
@include add-gutter(1/6 at $bkpt-1);
@include add-gutter(1/3 at $bkpt-2);
.main {
@include grid-span(3, 1);
@include breakpoint($bkpt-1) {
@include grid-span(1, 2);
}
@include breakpoint($bkpt-2) {
@include grid-span(1, 2);
}
}
.first {
@include grid-span(1, 2);
clear: both;
@include breakpoint($bkpt-1) {
@include grid-span(1, 1);
}
@include breakpoint($bkpt-2) {
@include grid-span(1, 3);
}
}
.second {
@include grid-span(1, 2);
clear: both;
@include breakpoint($bkpt-1) {
@include grid-span(1, 1);
clear: left;
}
@include breakpoint($bkpt-2) {
@include grid-span(1, 1);
}
}
// `layout-at` mixin can alternately be used for responsive grids
$grid-1: (
'grid': 1.618 2.61792,
'gutter': 1/6
);
.second {
@include grid-span(1, 2);
clear: both;
@include layout-at($grid-1, 700px) {
@include grid-span(1, 1);
clear: left;
}
}
// Intrinsic Ratio mixin from [Toolkit](https://github.com/team-sass/toolkit)
Slides available at
http://snugug.github.io/responsive-grids