2014-05-03 29 views
2

我試圖創建一個SASS兩種顏色主題有以下混入的幫助:顏色主題與上海社會科學院混入

@mixin theme($name, $bgColor, $textColor) { 
    .#{$name}{ 
    blockquote { 
     @include borderLeft($textColor, $basicUnit/2); 
    } 
    strong { 
     @include doubleFrame($bgColor, $textColor, 1px); 
    } 
    .highlighted { 
     @include highlight($textColor); 
    } 
    .bb-custom-side.left .content-title { 
     color: $textColor; 
    } 
    .content > h2 { 
     border-top:$basicUnit/2 solid $bgColor; 
    } 
    .content { 
     background: $bgColor; 
     color: $textColor; 
    } 
    } 
} 

然後就是打電話

@include theme("odd", $blue, $white); 
@include theme("even", $green, $black); 

我_layout.scss

但我一直得到這個錯誤,不知道我的mixin有什麼問題:

Syntax error: Invalid CSS after "...ily : "#{$name}": expected string, was "_#{$nameWeight}"";" 
     on line 31 of /Users/Works/html/assets/scss/_typography.scss 
     from line 11 of /Users/Works/html/assets/scss/main.scss 
Use --trace for backtrace. 

一個新手的問​​題...

感謝

+0

請提供足夠的代碼的錯誤可以被複制(也有不確定的混入和變量)。 – cimmanon

回答

1

這似乎與你正在使用您的theme混入內混入的一個問題(我懷疑它是與highlight因爲這似乎是唯一一個處理font-family(在錯誤的跟蹤中提到)。

刪除那些其他混入的電話,這樣的:

@mixin theme($name, $bgColor, $textColor) { 
    .#{$name}{ 
    .content { 
     background: $bgColor; 
     color: $textColor; 
    } 
    } 
} 

@include theme("odd", 'blue', 'white'); 

產生以下:

.odd .content { 
    background: "blue"; 
    color: "white"; 
} 

這似乎是你想要的。

Codepen

+0

謝謝,還有就是來自字體混入另一個錯誤:'@mixin字體( $名稱:APERCU, $類型:靜態, $ nameWeight:輕, $大小:1.0em, $ lineHeight是:1.4em, $體重:正常, $風格:正常, $變種:正常 ){ @if $類型= '靜態'{$ 家人: 「#{$ name}的_#{$ nameWeight}」; } @else { $ family:「#{$ name}」; } font:$ style $ variant $ weight $ size「/」$ lineHeight $ family,'Helvetica Neue',sans-serif; }'這會給出這個未定義變量的錯誤:「$ family」 – jewels

+0

您需要在''if''/''@ else''塊之外定義''family''。控制塊中定義的變量(例如'@ if'')在mixin塊的其餘部分中不可用。你可以在你的@if語句之前通過將它設置爲null來像這樣''family:null''來解決這個問題。有關更多解釋,請參見[this](http://stackoverflow.com/a/15372344/1048479)。這是一個工作[codepen](http://codepen.io/anon/pen/nwzgJ) –

+0

謝謝,非常有幫助。現在所有的作品:) – jewels

相關問題