Sass入門-基本特性
阿新 • • 發佈:2018-11-24
四、基本特性
宣告變數
使用$開頭:在值後面加!default表示預設值。eg:
$btn-primary-color : #fff !default;
在預設變數之前重新聲明後即可覆蓋它:$baseLineHeight: 2; $baseLineHeight: 1.5 !default; body{ line-height: $baseLineHeight; } 編譯後的css程式碼: body{ line-height:2; }
區域性變數和全域性變數
//SCSS
巢狀
1.選擇器巢狀<header> <nav> <a href=“##”>Home</a> <a href=“##”>About</a
2.屬性巢狀
.box { border-top: 1px solid red
3.偽類巢狀
.clearfix{ &:before, &:after { content:""; display: table; } &:after { clear:both; overflow: hidden; } } 編譯後: clearfix:before, .clearfix:after { content: ""; display: table; } .clearfix:after { clear: both; overflow: hidden; }
注意:避免選擇器巢狀!