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

Conditional assignments

In this recipe, you will learn how to perform a conditional assignment of a variable or a property with SassScript.

Getting ready

Read the Installing Sass for command line usage recipe of Chapter 1, Getting Started with Sass, to find out how to compile your SCSS code into CSS code.

How to do it...

Perform the following step to learn more about conditional assignments in Sass:

  1. Use your text editor to create a Ruby file called if.rb. Write down the following SCSS code into this file:

    // scss-lint:disable ColorKeyword
    $dark: true;
    $dark-color: black;
    $light-color: white;
    .element {
      color: if($dark, $dark-color, $light-color);
  2. Then, run the following command in your console to compile the Sass template from the first step into CSS code:

    sass if.scss
  3. Finally, a CSS code like the one shown here should be outputted in your console:

    .element {
      color: black; }

How it works

The condition if() function should be called with three parameters. The first parameter sets the condition...