1
我有2個類風格的標題。然後,我需要創建一個mixin來定製背景模式,具體取決於顯示哪個頭。調用類變量insida一個混合 - Sass
是否可以在我的mixin中使用$ has-dept變量?
//header 1
.dt-style-user-bar-without-departments {
@extend .dt-style-user-bar;
$has-dept: false;
/...
}
//header 2
.dt-style-user-bar-with-departments {
@extend .dt-style-user-bar;
$has-dept: false;
//...
}
//intending to get $has-dept var to give the proper background color
@mixin set-reveal-bg-color(){
@extend $has-dept;
@if $has-dept {
background: green !important;
}
@else {
background: blue !important;
}
}
//prints the background color in the modal overlay class
.reveal-modal-bg{
@include set-reveal-bg-color()
}
*輸出:錯誤SCSS/app.scss(線SCSS/_dt_style.scss 471:未定義的變量: 「$有-部門」。)*
不能使用'@ extend'指令變量,它僅適用於選擇器。來自[SASS reference](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#extend):'@ extend'指令通過告訴Sass一個**選擇器**應該繼承這些樣式來避免這些問題另一個**選擇器** [...] –
你能展示你想在CSS中實現什麼嗎? –