2012-06-21 53 views
0

我正在爲SCSS構建一個mixin,我想知道它可以添加一個aditional值,具體取決於參數。這是我所嘗試過的。一切正常,但@if條件:SCSS:在多個CSS語句中間的條件

@mixin fontFace($fontName, $path: "", $weight: normal, $style: none, $fileName: $fontName, $svg:0) { 
    @font-face { 
     font-family: $fontName; 
     src: url("#{$path}#{$fileName}.eot"); 
     src: url("#{$path}#{$fileName}.eot?iefix") format("eot"), 
       url("#{$path}#{$fileName}.woff") format("woff"), 
       url("#{$path}#{$fileName}.ttf") format("truetype") 
       @if $svg != 0 { 
        , url("#{$path}#{$fileName}.svg##{$fileName}") format("svg"); 
       }else{ 
        ; 
       } 
     font-weight: $weight; 
     font-style: $style; 
    } 
} 

回答

1

如何如下:

@mixin fontFace($fontName, $path: "", $weight: normal, $style: none, $fileName: $fontName, $svg: false) { 
    $src: url("#{$path}#{$fileName}.eot?iefix") format("eot"), 
      url("#{$path}#{$fileName}.woff") format("woff"), 
      url("#{$path}#{$fileName}.ttf") format("truetype"); 

    @if $svg == true { 
     $src: $src, 
       url("#{$path}#{$fileName}.svg##{$fileName}") format("svg"); 
    } 

    @font-face { 
     font-family: $fontName; 
     src: url("#{$path}#{$fileName}.eot"); 
     src: $src; 
     font-weight: $weight; 
     font-style: $style; 
    } 
} 
+0

+1聽起來像一個極好的解決方案,我'只是想知道是否有可能與一些類似於我句法... – meo