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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the Sass interactive mode and SassScript


In the Using Sass on the command line recipe of this chapter, you had to create a Sass sample as an input for the Sass compiler. In this recipe, you will be introduced to the interactive Sass mode and SassScript. SassScript is a small set of extensions of the plain CSS property syntax. You can use SassScript to set property values using variables, arithmetic, and extra functions. The interactive mode enables you to enter and test your SassScript code directly in the console. SassScript can also be used to generate selectors and property names via string interpolation. You can read more about interpolation in the Interpolation of variables recipe of Chapter 3, Variables, Mixins, and Functions.

Getting ready

The interactive mode of Sass comes with the Sass gem. You can use it after installing Sass. In the Installing Sass for command line usage recipe of this chapter, you can read how to install Sass.

How to do it...

Take a look at the following steps to understand how to use the Sass interactive mode:

  1. You can start the interactive shell by running the following in your console:

    sass -interactive
    
  2. Now, you can enter the following code into the shell:

    >> 1px + 1px
    
  3. The preceding command will give the following output:

    2px
    
  4. Also, notice that you can only enter a valid code. Consider the following code:

    >> 1px + 2em
    
  5. Because Sass cannot sum different units, the preceding code will generate the following error:

    SyntaxError: Incompatible units: 'em' and 'px'.
    
  6. Also, Sass built-in function can be evaluated. Enter the following code into the shell:

    change-color(#ff0000, $alpha: 0.5)
    
  7. You will find that this returns the following output:

    rgba(255, 0, 0, 0.5)
    

How it works...

As it has already been made clear in the introduction of this recipe, you can use the interactive shell to test the property values set by SassScript. The interactive shell does not allow you to use variables or mixins, but you can make use of Sass's built-in functions. Chapter 5, Built-in Functions, of this book will introduce you to the useful built-in functions of Sass. The function used in the fourth step of this recipe is an example of a built-in function.

To quit once you have entered the interactive mode, just type Ctrl + D.

There's more...

The Compass gem has an interactive shell that is available too. You can start Compass's interactive shell by running the following command in your console:

compass interactive

In the interactive shell, you can run SassScript and you can also test the results of the Compass helper functions. Try the following command to evaluate the append-selector() helper function:

>> append-selector("p, div, span", ".bar")

The preceding command will give the following output:

"p.bar, div.bar, span.bar"

In your Sass code, you should use the preceding result inside an interpolation escape: #{ }.