Sassの@extend の応用
同じルールセット内に複数の@extendを指定。
scss(継承元,_extend.scss)
.first{ font-size: 36px; text-indent: 1em; span{ font-size: 80%; color: #666; } } .second{ font-size: 24px; text-indent: 0.7em; span{ font-size: 18px; color: #999; } } .accentBG{ background: #F4060A; } .ligthBG{ background: #AB9696; }
scss(継承先)
@import "_extend.scss)"; dl{ dd#main{ @extend .first; @extend .accentBG; } dd#sub{ @extend .second; @extend .lightBG; } }
.first, dl dd#main { font-size: 36px; text-indent: 1em; } .first span, dl dd#main span { font-size: 80%; color: #666; } .second, dl dd#sub { font-size: 24px; text-indent: 0.7em; } .second span, dl dd#sub span { font-size: 18px; color: #999; } .accentBG, dl dd#main { background: #F4060A; } .ligthBG { background: #AB9696; }
@extendの連鎖継承
scss
.first{ font-size: 36px; text-indent: 1em; span{ font-size: 80%; color: #666; } } .accentBG{ //.firstを継承 @extend .first; background: #F4060A; } dl{ dd{ @extend .accentBG; } }
.first, .accentBG, dl dd { font-size: 36px; text-indent: 1em; } .first span, .accentBG span, dl dd span { font-size: 80%; color: #666; } .accentBG, dl dd { background: #F4060A; }