Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Sass and Compass Designer's Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Sass and Compass Designer's Cookbook

Sass and Compass Designer's Cookbook

By : Jobsen, Stuart Robson
5 (2)
close
close
Sass and Compass Designer's Cookbook

Sass and Compass Designer's Cookbook

5 (2)
By: 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 (18 chapters)
close
close
17
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: #{ }.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Sass and Compass Designer's Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon