$width: 5em; #main { width: $width; }
嵌套引用在其餘編程語言中便是字符串插值,須要用#{}進行包裹:編程
$left: left; .div { border-#{$left}-width: 5px; }
將一個選擇器下的全部樣式繼承給另外一個選擇器。編程語言
.error { border: 1px #f00; background-color: #fdd; } .error.intrusion { background-image: url("/image/hacked.png"); } .seriousError { @extend .error; border-width: 3px; }
=>ide
.error, .seriousError { border: 1px #f00; background-color: #fdd; } .error.intrusion, .seriousError.intrusion { background-image: url("/image/hacked.png"); } .seriousError { border-width: 3px; }
@mixin left { float: left; margin-left: 10px; } div { @include left; }
@mixin left($value: 10px) { float: left; margin-right: $value; } div { @include left(20px); }
@if lightness($color) > 30% { background-color: #000; } @else { background-color: #fff; }
@for $i from 1 to 10 { .border-#{$i} { border: #{$i}px solid blue; } }
$i: 6; @while $i > 0 { .item-#{$i} { width: 2em * $i; } $i: $i - 2; }
@function double($n) { @return $n * 2; } #sidebar { width: double(5px); }