develop with

Conditions

Sass supports conditions for setting up styles based on variables.

Conditions

Sass supports conditions for setting up styles based on variables. These really come in handy when you are defining methods and mixins. The conditions in Sass support an if, else if and else syntax similar to other languages.

Example:

$environment: dev
$grid-color: #c0c0c0

div.grid
  @if $environment == dev
    border: 1px solid $grid-color
  @else if $environment == qa
    border: 1px solid lighten($grid-color, 25%)
  @else
    border: 0

Tip: Arc90 SASS Color Tool is handy for getting color based function definitions for SASS.

In the above example, the else isn’t really needed and is used just for illustration purposes.

Next: Loops

comments powered by Disqus

Want to see a topic covered? create a suggestion

Get more developer references and books in the developwith store.

Sass Language
Sass Reference list
List of how tos for Sass