A Complete Tutorial To Susy
A Complete Tutorial To Susy
A Complete Tutorial To Susy
1 of 13
Important Update
Susy 2 is now released, which makes this tutorial obsolete. Head over here to nd the latest
article on Susy 2 instead.
Installing Susy
Susy requires Sass and Compass.
This tutorial assumes that you already have Sass and Compass installed. If not, I suggest you
check out some awesome video tutorials at LevelUpTuts for Sass and Compass.
Once you have Sass and Compass installed, go ahead and install Susy from the command line:
# Command line
$ sudo gem install susy
Important Note: Susy has been upgraded to Susy 2, and a lot of the congurations is changed.
If you have any errors running Susy, I would recommended you to uninstall all versions of Sass,
Compass and Susy, and reinstall them altogether. The most important thing here is that sass
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
2 of 13
and compass needs to upgrade if you are using old versions (I have no clue how to update so I
just reinstalled everything)
# I personally use --pre, but you should be able to get by without the --pre since Susy 2.0 was officially released
sudo gem install sass --pre
sudo gem install compass --pre
sudo gem install susy --pre
The process to use Susy in a project is to add a line of code in the cong.rb found in the
compass.
# in config.rb
require 'susy'
Setting up Susy
The very rst step of using Susy in your project is to import Susy in your sass le and set its
defaults.
@import "_normalize.scss";
// To revert all browser default styles
@import "susyone";
// susy is now reserved for susy 2. For the rest of this tutorial, you have to use susyone instead of importing "su
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
3 of 13
$gutter-width: 1rem;
$grid-padding: $gutter-width / 2;
Ill also recommend using border boxes to help you with creating layouts. Susy has a built-in
mixin for border-box sizing. Read on about border-box over at CSS Tricks if have no idea what it
is.
@include border-box-sizing;
Also, the susy grid background helps alot when trying to understand how columns are placed.
.container {
@include susy-grid-background;
}
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
4 of 13
The HTML
The HTML for the grid test is as follows.
<div class="container">
<h1>The 10 column complex nested grid AG test</h1>
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
5 of 13
<h2>AG 5</h2>
</div>
<div class="ag ag6">
<h2>AG 6</h2>
</div>
<!-- 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 -->
</div>
<!-- /container -->
Simply speaking, whenever something is found within another div, you should nest it within the
previous div.
In our case, AG 3 to AG 7 will be nested under AG 2 while AG 8, AG 9 and AG 10 are nested under
AG 7.
The Sass
Were going give each ag a color like the one on Susys main webpage.
/**
* Styles for AG grids & Container
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
6 of 13
*/
.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;
}
/**
* Text Styles
*/
h2 {
text-align: center;
font-size: 1rem;
font-weight: normal;
padding-top: 1.8rem;
padding-bottom: 1.8rem;
}
6/10/2014 12:38 PM
7 of 13
Before diving into writing susy mixins, I hope you wont mind if I explained how they work.
Container
Container establishes the grid containing element for the webpage. Given our html, the
container mixin will be applied to the container class. This tells Susy where to start all the
calculations from.
.container {
@include container;
}
If were are to use Susy with responsive design, we have to pass some arguments into container.
This will be elaborated on in part 2 of the tutorial.
Span Columns
The Span Column mixin is probably the one used most while using Susy. It allows you to align
an element to the grid you would like dened.
The span column mixin takes a minimum of 1 argument and has the potential to accept a few
more to customize to your needs.
The most important arguments to be included here in span-columns are $columns, omega and
$context. The rest of the explanation can be viewed on the Susy Reference page.
$columns means the number of columns you would like the particular element to take up.
omega is an optional ag to tell Susy that this is the nal element in a row.
$context tells Susy the current nesting context. It defaults to the total number of columns you
specied within the container. In our case, it is 10.
Since were clear of the two basic mixins used, we can start applying them to create the grid.
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
8 of 13
.container {
@include container;
overflow: hidden;
}
Lets start applying susy span column mixins to the rest of our grids. Taking the image as a
reference, we count that ag1 takes up 2 columns, ag2 takes up 6 columns and ag3 takes up the
nal two columns.
.ag1 {
@include span-columns(2);
}
.ag2 {
@include span-columns(6, 10);
// Optionally, you can choose to include the context.
}
.ag3 {
@include span-columns(2 omega);
// The omega flag is set here to tell Susy that ag3 is the final column.
}
.container {
*zoom: 1;
// Susy has calculated and provided fallbacks in px for the rem unit I used
max-width: 784px;
max-width: 49rem;
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
9 of 13
_width: 784px;
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
overflow: hidden; }
.ag1 {
width: 18.36735%; // Size of 2 columns + 1 Gutter
float: left;
margin-right: 2.04082%;
display: inline; }
.ag2 {
width: 59.18367%; // Size of 6 columns + 5 Gutters
float: left;
margin-right: 2.04082%;
display: inline; }
.ag3 {
width: 18.36735%;
float: right; // Omega flag creates a float right instead of float left
margin-right: 0;
*margin-left: -1rem;
display: inline; }
Susy takes into account the containers width at 49rem (or 784px) and proceeds to convert all
our calculations into percentages. Its alot simpler to work with numbers like 2 and 6 instead of
absolute percentages!
Although this doesnt seem like much right now, you will see that its extremely awesome when
responsive design comes into play in the next tutorial.
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
10 of 13
Lets proceed to complete the rest of the grids that are within AG 2.
.ag2 {
// overflow hidden is used to self clear children
overflow: hidden;
}
.ag4 {
// Specifying the context with 6
@include span-columns(3, 6);
}
.ag5 {
// Additionally, adding omega to signify the last column
@include span-columns(3 omega, 6);
}
.ag6 {
@include span-columns(2, 6);
}
.ag7 {
@include span-columns(4 omega, 6);
}
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
11 of 13
.ag7 {
overflow: hidden;
}
.ag8 {
@include span-columns(2, 4);
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
12 of 13
.ag9 {
@include span-columns(2 omega, 4);
}
.ag10 {
// There is no need to use span columns on AG 10 since elements take up 100% of the space by default in display b
clear: both;
// You can still use span-columns if you want to though. There's no fault in using that.
@include span-columns(4, 4);
}
Feel free to grab the source code and view the demo:
View Demo
Download Source
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM
13 of 13
http://www.zell-weekeat.com/a-complete-tutorial-to-susy/
6/10/2014 12:38 PM