-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Sass and Compass Designer's Cookbook
By :
In this recipe, you will learn how to create iterations by using for loops in Sass.
Read the Installing Sass for command line usage recipe of Chapter 1, Getting Started with Sass, to find out how to use Ruby Sass on the command line. If you are not familiar with for-loops already, try to study for-loops in other programming languages.
Learn how to use for loops in Sass by performing the following steps:
Create a Sass file called iteration.scss that will contain an SCSS code like that shown here:
@for $i from 1 to 4 {
.font-size-#{$i} { font-size: 0.8em * $i; }
}Then run the following command in your console:
sass --compass iteration.scss
After running the command from the previous step, the following compiled CSS will be outputted in your console:
.font-size-1 {
font-size: 0.8em; }
.font-size-2 {
font-size: 1.6em; }
.font-size-3 {
font-size: 2.4em; }Those who are already familiar with using for loops in other programming languages...
Change the font size
Change margin width
Change background colour