Documente Academic
Documente Profesional
Documente Cultură
1 of 9
Breakpoint Helpers
Susy Two doesnt come with a breakpoint mixin by default. Instead, it recommends you to use
the breakpoint gem to help with writing media queries.
Were rst going to install and import this gem.
Breakpoint requires Compass. To use it youll need to have both gems installed.
# config.rb
require 'breakpoint'
// styles.scss
@import "breakpoint";
Using Breakpoint
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM
2 of 9
One thing I like about using Breakpoint is that it is super easy to make mobile rst breakpoints.
Let me explain.
To use breakpoint, youll have to call the breakpoint mixin and insert a set of arguments to it.
These arguments will eventually turn out to be media queries.
@include breakpoint(<args>) {
/* contents */
}
The beauty of this mixin is that if you pass in only one argument, it automatically becomes
mobile-rst oriented. This argument should be a min-width of the breakpoint youre looking for.
// styles.scss
.container {
@include breakpoint(1200px) {
/* contents */
}
}
This translates to
/* style.css */
@media (min-width: 1200px) {
.container {
/* contents */
}
}
The breakpoint mixin is super exible and you can make ultra complicated arguments if you
would like to.
6/10/2014 6:27 PM
3 of 9
browser, and after 900px, they would be laid out in the 10 colum AG grid layout like in the
previous tutorial.
To accomplish this, you just have to add the breakpoint correctly in the stylesheet. An example
of AG1 would be
.ag1 {
// Mobile Styles here
@include breakpoint(900px) {
@include span(2 of 10);
}
}
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM
4 of 9
We didnt need add any specic styles to the mobile section. since A div would take up a width
of 100% by default, At 900px, we have to add a media query (I call them breakpoints for short) ,
and make it oat according to the susy grid.
Since
breakpoint(900px)
translate to
min-width(900px)
in media queries,
span(2 of 10)
will only
trigger when the browser width is larger than 900px. This workow is also perfect for mobile
rst styling.
By the same theory, AG2 and AG3 would use similar styles:
.ag2 {
// Mobile Styles here
@include breakpoint(900px) {
@include span(6 of 10);
@include clearfix;
}
}
.ag3 {
// Mobile Styles here
@include breakpoint(900px) {
@include span(2 of 10 last);
}
}
Okay thats all nice and good. But what if you wanted something slightly more complicated?
Note: If you dont want to use breakpoint by any chance, you can still use plain old queries with
the same steps.
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM
5 of 9
This is a little more challenging compared to the previous breakpoint. Because AG1 seems to
have switched positions all the way to the right! How did that happen?!
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM
6 of 9
last
keyword.
.ag1 {
// tablet view
@include breakpoint(600px) {
@include span(2 of 6 last);
}
// desktop view
@include breakpoint(900px) {
@include span(2 of 10);
}
}
.ag2 {
@include clearfix;
// tablet view
@include breakpoint(600px) {
@include span(4 of 6);
}
// desktop view
@include breakpoint(900px) {
@include span(6 of 10);
}
}
.ag3 {
// tablet view
@include breakpoint(600px) {
@include span(2 of 6 last);
}
// desktop view
@include breakpoint(900px) {
@include span(2 of 10 last);
}
}
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM
last
7 of 9
last
keyword to the
span
mixin.
keyword tells Susy to oat the element right instead of the default oat left, hence
/* style.css */
@media (min-width: 600px) {
.ag1 {
width: 31.03448%;
float: right;
}
}
@media (min-width: 900px) {
/* line 24, ../sass/styles.scss */
.ag1 {
width: 18.36735%;
float: left;
margin-right: 2.04082%;
}
}
Thats the trick to it! (PS, I also expanded AG2 with some paddings and added margin bottom to
AG1 in the tablet view to make it look nicer).
susy-breakpoint
allowing a DRY-er Sass if you need to include multiple span declarations within the same
breakpoint and layout.
The syntax for
susy-breakpoint
is:
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM
8 of 9
In this case, the following two codes are equivalent. Notice how the context (of 6) is lifted up
from the span and placed into the breakpoint instead.
.ag1 {
@include susy-breakpoint(600px, 6) {
@include span (2 last);
}
}
.ag1 {
@include breakpoint(600px) {
@include span(2 of 6 last);
}
}
I personally prefer the second method (just using breakpoint), but you can feel free to pick
either version since theres no dierence in their output.
At this point, you may have noticed that it can be a little unsightly to allow the uid container to
go full width if desktop sizes are huge. Lets x that.
.container {
@include container(1140px);
}
max-width
.container {
@include container;
max-width: 1140px;
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM
9 of 9
Unfortunately, we cant do the same with a static grid, because Susy handles all the math and
calculates the max width at the same time. To deal with static grids, we have to use a slightly
dierent approach.
Lets leave that for the next tutorial.
http://www.zell-weekeat.com/susy2-tutorial-2/
6/10/2014 6:27 PM