2015-06-03 100 views
2

我目前正在編寫一個mixin,以便在一行中輕鬆添加多個字體。在混入我寫的都是我想用這樣的權重:Sass將黑色自動轉換爲#000000

$font-weights: (
"hairline": 100, 
"thin": 200, 
"light": 300, 
"regular": 400, 
"medium": 500, 
"semibold": 600, 
"bold": 700, 
"heavy": 800, 
"black": 900, 
); 
$main-font: "Lato"; 
@include font-list($main-font,Hairline Thin Light Regular Medium SemiBold Bold Heavy Black, normal, $font-weights); 

在@include給予權重的列表中的最後權重是「黑」,所有環節順利,但混入我使用會給最後一個值帶來錯誤,因爲在使用#000000之前,它會以某種方式自動轉換「黑色」。

有什麼辦法讓Sass不這樣做?

的密新的(S):

@mixin font-include($name, $file, $weight, $type) { 
    @include font-face("#{$name}", font-files("#{$file}.woff", "#{$file}.ttf"), "#{$file}.eot", $weight, $type); 
} 

@mixin font-list($name,$weights,$type,$font-weight){ 
    @for $i from 1 through length($weights) {  
     @include font-include($name,#{$name}-#{nth($weights,$i)},map-get($font-weight,#{to-lower-case(nth($weights,$i))}),$type); 
    } 
} 

通過指南針給出的錯誤是:

$string: #000000 is not a string for `to-lower-case' 

回答

0

使用在所有的權重混入引文結束固定它。

(並增加了斜體字體的功能)。

@mixin font-list($name,$weights,$type,$font-weight){ 
    $italic: ''; 
    @if $type == 'italic'{ 
     $italic: 'Italic'; 
    } 
    @for $i from 1 through length($weights) { 
     $weight: unquote("#{nth($weights,$i)}"); 
     @include font-include($name,#{$name}-#{nth($weights,$i)}#{$italic},map-get($font-weight,#{to-lower-case($weight)}),$type); 
    } 
} 
相關問題