In Chapter 1, Getting started with Sass and Compass, we looked briefly at nesting. It provides the ability to nest styles within one another. This provides a handy way to write mini blocks of modular code.
With a normal CSS style declaration, there is a selector, then an opening curly brace, and then any number of property and value pairs, followed by a closing curly brace. For example:
.css { display: block; }
Where Sass differs is that before the closing curly brace, you can nest another rule within. What do I mean by that? Consider this example:
a { color: $color7; &:hover,&:focus { color: $color5; } &:visited,&:active { color: $color4; } }
In the previous code, a color has been set for the link tag using a variable. Then the hover
and focus
state have been nested within the main anchor style with a different color set. Furthermore, styles for the visited and active state have been nested...