1 of 14
Susy is a helper tool that lets you created ultra customizable grids on the y easily.
Its been a while since Susy 2 is ocially released. If you loved Susy 1, you will denitely love to use
Susy 2 because it oers so much more exibility.
This is a two part tutorial for Susy 2, and in this tutorial, I will be sharing with you how to create the
Complex AG Grid with Susy 2.
Why Susy?
As I mentioned, Susy is a helper tool that lets you create any kind of grids easily without the need
do a ton of math. The beauty about Susy is that it separates presentational CSS from the HTML.
If you have used traditional grid frameworks like Foundation and Bootstrap before, you already
know that the grids that come with these frameworks already have xed widths and breakpoints.
Furthermore, classes have to be added to the HTML if you decide to change your layout.
Susy removes this layer altogether. You can immediately target any css class and apply a grid to it.
Yeah I know this is totally abstract and its dicult to grasp. Instead of only talking about theory,
we are going to use Susy 2 to help us build a complicated grid system devised by Arnaud Guera
(AG) that uses 10 columns. This grid looks like this
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
2 of 14
Installing Susy 2
If You Dont Already Have Susy Installed
Susy requires you to have both Sass installed. If you dont have them installed, you can install
them with the following commands
If this doesnt work, it means you need to try the next method , or install Ruby RVM rst.
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
3 of 14
The second method to installing Susy 2 is a little more manual. Its to uninstall the two gems
mentioned above and reinstall them. Its the best way to avoid any errors if you didnt go by the
update route.
Now that youre done installing Susy 2, we can now begin setting Susy 2 up.
Setting Up Susy 2
Likewise to the previous version, you need to require susy in the cong.rb le if you were to use
Susy 2.
# config.rb
require 'susy'
// Importing Susy
@import 'susy';
Susy 2 has list of global defaults that are built into it. You can change the defaults with the code
Youll want to play around with the defaults and try them out depending on how you want to work
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
4 of 14
with Susy. Ill go a little deeper regarding these defaults in another tutorial. You can use Susy with
the defaults immediately now, but since I love working with border-box and rem units, Im going to
change some defaults.
$susy: (
global-box-sizing: border-box,
use-custom: (rem: true
)
);
Note that Susy uses a uid layout by default. This means that width of the outer containing
element will be 100%.
If you like to use Susy with xed widths at certain breakpoints instead, change the
static
math
key to
. The major dierence between these two modes come in when responsifying your styles,
@import "normalize";
@import "compass";
@import "susy";
@include border-box-sizing;
8/18/2014 12:58 AM
5 of 14
<div class="container">
<h1>The 10 column complex nested grid AG test</h1>
<!-- ag8, ag9 and ag10 are nested within ag7 -->
<div class="ag ag7">
<h2>AG 7</h2>
<div class="ag ag8">
<h2>AG 8</h2>
</div>
<div class="ag ag9">
<h2>AG 9</h2>
</div>
<div class="ag ag10">
<h2>AG 10</h2>
</div>
</div>
<!-- /ag7 -->
</div>
<!-- /ag2 -->
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
6 of 14
</div>
<!-- /container -->
Simply speaking, whenever something is found within another div, you should nest it within the
previous div.
In this case, AG 4 to AG 7 will be nested under AG 2 while AG 8, AG 9 and AG 10 are nested under AG
7.
The CSS for the grid backgrounds will remain the same as well.
/**
* Styles for AG grids & Container
*/
.container {
background-color: #fbeecb;
}
.ag1, .ag3 {
background-color: #71dad2;
}
.ag2 {
background-color: #fae7b3;
}
.ag4,.ag5,.ag8,.ag9 {
background-color: #ee9e9c;
}
.ag6 {
background-color: #f09671;
}
.ag7 {
background-color: #f6d784;
}
.ag10 {
background-color: #ea9fc3;
}
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
7 of 14
/**
* Text Styles
*/
h2 {
text-align: center;
font-size: 1rem;
font-weight: normal;
padding-top: 1.8rem;
padding-bottom: 1.8rem;
}
Now that were all prepped up, we can dive into the some more Susy details.
The container mixin has an optional length argument, with allows you to set a max width to the
container. If this number is not found, Susy will default to
max-width: 100%;
instead.
If you are using static grids, Susy advises that you should make it auto instead and let Susy
calculate the max width for you.
To keep it auto, you can omit the length argument.
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
8 of 14
@include container;
Span (Mixin)
The span mixin is the heart of Susy layouts. Susy made it extremely exible.
I generally follow the Susy way for writing my layouts.
@include span(
If you used Susy 1, you would have noticed that this is very similar to the
span-column
mixin, with
[<wide / wider>]
is a optional argument lets you expand the width of the column to include 1 or 2
<layout>
is the context of the container, along with other optionals that dene the layout.
(Context refers to the number of columns the parent container is made up of).
[<last>]
is an optional argument that tells Susy that this element is supposed to be the last item
in the row.
An example of this at work is
// This has a width of 3 columns + 1 gutter, out of 9 columns and is supposed to be the last item within the context.
.some-selector {
@include span(3 wide of 9 last);
}
Span (Function)
The Span function is similar to the span mixin, with the exception that it only returns the width of
the element. You will only need the
http://www.zell-weekeat.com/susy2-tutorial/
<width>
<wide/ wider>
and
<layout>
here.
8/18/2014 12:58 AM
9 of 14
This span function makes life a ton easier by not having the need to remember any margins or
padding mixins that susy previously uses. Now, you can just use the span function to get the
correct width to pad.
Gutter Function
The gutter function takes only one argument, the context.
These are all the important functions you need to know when using Susy 2.
.container {
@include container;
}
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
10 of 14
Since we also know that the container is going to hold oated elements, were gonna give it a
clearx.
.container {
// This is the default clearfix from Compass. You can opt to use other clearfix methods
@include clearfix;
}
We rst need to create the layouts on AG1, AG2 and AG3. Upon inspection, the whole container is
supposed to take up 10 columns, where AG1 and 3 are to take up 2 columns each and the rest is
taken up by AG2. AG2 needs a clearx as well since its going to be a container for AG 4 to AG 10.
.ag1 {
@include span(2 of 10);
}
.ag2 {
@include span(6 of 10);
@include clearfix;
}
.ag3 {
@include span(2 of 10 last);
}
If you take a look at the output now, you should see this
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
11 of 14
AG4 and AG5 are nested within AG2 and they each hold a width of 3 columns each
.ag4 {
@include span(3 of 6);
}
.ag5 {
@include span(3 of 6 last);
}
Alternatively, you can make use of the last mixin and write it this way. The last mixin just changes that element to
.ag4,.ag5 {
@include span(3 of 6);
}
.ag5 {
@include last;
}
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
12 of 14
AG6 holds 2 columns and AG 7 holds 4 columns, and AG 7 is the last item in the row. You should
probably know the drill by now.
.ag6 {
@include span(2 of 6);
}
.ag7 {
@include span(4 of 6 last);
@include clearfix;
}
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
13 of 14
And lets nish up the last few items for the AG Grid
.ag8 {
@include span(2 of 4);
}
.ag9 {
@include span(2 of 4 last);
}
.ag10 {
clear: both;
// Alternatively, you can now use the span mixin with the full keyword to tell Susy this should be a 100% width
// @include span(full);
}
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM
14 of 14
http://www.zell-weekeat.com/susy2-tutorial/
8/18/2014 12:58 AM