Book Image

Sass and Compass Designer's Cookbook

By : Bass Jobsen, Stuart Robson
Book Image

Sass and Compass Designer's Cookbook

By: Bass Jobsen, Stuart Robson

Overview of this book

Sass and Compass Designer's Cookbook helps you to get most out of CSS3 and harness its benefits to create engaging and receptive applications. This book will help you develop faster and reduce the maintenance time for your web development projects by using Sass and Compass. You will learn how to use with CSS frameworks such as Bootstrap and Foundation and understand how to use other libraries of pre-built mixins. You will also learn setting up a development environment with Gulp. This book guides you through all the concepts and gives you practical examples for full understanding.
Table of Contents (23 chapters)
Sass and Compass Designer's Cookbook
About the Author
About the Reviewers

Using @for

In this recipe, you will learn how to create iterations by using for loops in Sass.

Getting ready

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.

How to do it...

Learn how to use for loops in Sass by performing the following steps:

  1. 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; }
  2. Then run the following command in your console:

    sass --compass iteration.scss  
  3. 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; }

How it works...

Those who are already familiar with using for loops in other programming languages...