官方文檔web
安裝rubysass
gem install sass
ruby
// 編譯格式 sass --watch input.scss:output.css --style compact // 添加調試map sass --watch input.scss:output.css --sourcemap // 開啓debug信息 sass --watch input.scss:output.css --debug-info
$blue : #1875e7; div { color : $blue; } $side : left; .rounded { border-#{side}-radius: 5px; }
body { margin: (14px/2); top: 50px + 100px; right: $var * 10%; }
div h1 { color: red; }
div { h1 { color: red; } }
p { border: { color: red; } }
a { &:hover { color: #ffb3ff; } } /* 使用&引用父元素 */
/* comment */
ide
// comment函數
/*! important comments! */
.class1 { border: 1px slid #ddd; }
.class2 { @extend .class1; font-size: 120%; }
可重用代碼塊。url
@mixin left { float: left; margin-left: 10px; }
div { @include left; }
指定參數和缺省值:debug
@mixin left($value: 10px) { float: left; margin-right: $value; }
div { @include left(20px); }
example:調試
@mixin rounded($vert, $horz, $radius: 10px) { border-#{$vert}-#{$horz}-radius: $radius; -moz-border-#{$vert}-#{$horz}-radius: $radius; -webkit-border-#{$vert}-#{$horz}-radius: $radius; }
#navbar li { @include rounded(top, left); } #footer { @include rounded(top, left, 5px) }
lighten(#cc3, 10%) // #d6d65c darken(#cc3, 10%) // #a3a329 grayscale(#cc3) // #808080 complement(#cc3) // #33c
@import "path/filename.scss";
@import "foo.css";
p { @if 1 + 1 == 2 { border: 1px solid; } @if 5 < 3 { border: 2px dotted; } }
@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; }
@each $member in a, b, c, d { .#{$member} { background-image: url("/image/#{$member}.jpg"); } }
#function double($n) { @return $n * 2; } #sidebar { width: double(5px); }