1.sass中能夠使用變量css
$company-blue: #1875e7; h1#brand { color: $company-blue; } #sidebar { background-color: $company-blue; }
ul.nav {float: right} ul.nav li {float: left;} ul.nav li a {color: #111} ul.nav li.current {font-weight: bold;}
ul.nav { float: right; li { float: left; a { color: #111; } &.current { font-weight: bold; } } }
#header ul.nav { float: right; } #header ul.nav li { float: left; margin-right: 10px; } #footer ul.nav { margin-top: 1em; } #footer ul.nav li { float: left; margin-right: 10px; }
@mixin horizontal-list { li { float: left; margin-right: 10px; } } #header ul.nav { @include horizontal-list; float: right; } #footer ul.nav { @include horizontal-list; margin-top: 1em; }
//混合器傳參使用 @mixin horizontal-list($spacing: 10px) { //$spacing的默認值爲10px,若是不傳參則使用此值; li { float: left; margin-right: $spacing; } } #header ul.nav { @include horizontal-list; //使用$spacing默認值,即10px; float: right; } #footer ul.nav { @include horizontal-list(20px); //賦予$spacing新值爲20; margin-top: 1em; }
//使用繼承@extend,避免重複輸出 .error { border: 1px #f00; background: #fdd; } .error.intrusion { font-size: 1.2em; font-weight: bold; } .badError { @extend .error; border-width: 3px; }
.error, .badError { border: 1px #f00; background: #fdd; } .error.intrusion, .badError.intrusion { font-size: 1.2em; font-weight: bold; } .badError { border-width: 3px; }
%button-reset { margin: 0; padding: .5em 1.2em; text-decoration: none; cursor: pointer; } .save { @extend %button-reset; color: white; background: #blue; } .delete { @extend %button-reset; color: white; background: red; }
.save, .delete { margin: 0; padding: .5em 1.2em; text-decoration: none; cursor: pointer; } .save { color: white; background: #blue; } .delete { color: white; background: red; }