...but are always worth mentioning, because they're incredibly cool compared to vanilla CSS:
Familiar way:
a {
&:hover {
color: red;
}
}
Compiles into:
/* compiled CSS */
a:hover {
color: red;
}
But can be used with a prefix just as well:
p {
body.no-touch & {
display: none;
}
}
Gives you:
/* compiled CSS */
body.no-touch p {
display: none;
}
p {
@media (max-width: 768px) {
// Use larger text for smaller screens:
font-size: 150%;
}
}
Compiles into:
/* compiled CSS */
@media (max-width: 768px) {
p {
font-size: 150%;
}
}
p {
@media (max-width: 768px) {
// Use larger text for smaller screens:
font-size: 150%;
@media (orientation: landscape) {
// Condense text a bit because of small vertical space:
line-height: 75%;
}
}
}
Compiles into:
/* compiled CSS */
@media (max-width: 768px) {
p {
font-size: 150%;
}
}
@media (max-width: 768px) and (orientation: landscape) {
p {
line-height: 75%;
}
}
$debug: false; // this would likely be in a _settings.scss somewhere
article {
color: black;
@if ($debug) {
border: 1px dotted red;
}
}
Compiles into:
/* compiled CSS */
article {
color: black;
}
There's also @for
, @each
and @while
.
TODO
TODO
http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html
No Ruby needed:
@function add-padding($toValue) {
@return $toValue + 20px;
}
p {
margin: add-padding(50px);
}
Compiles into:
/* compiled CSS */
p {
margin: 70px;
}
@mixin foobar($a, $b, $padding: 20px) {
// do something with all these arguments...
}
p {
@include foobar(123, "abc");
}
p.important {
@include foobar(123, "abc", 50px);
}
If you have a huge helper with:
@mixin foobar($a: 1px, $b: 2px, $c: 3px, $d: 4px, $e: 5px) {
// do something with all these arguments...
}
p {
@include foobar($c: 50px); // specify only the argument you want to override
}
...and expanding and/or extending during further calls.
...or almost anywhere else, for that matter.
...with multiple inheritance.