2013-08-05 43 views
0

CSS混入少混入返回Nanpx

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (@font-scale > 0) { 
    @new-font-size: round(@base-font-size * pow(@base-scale-factor, @font-scale)); 
    font-size: @new-font-size; 
    line-height: ceil((@new-font-size/(@base-line-height * @base-font-size))) * (@base-line-height * @base-font-size); 
} 

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (@font-scale = 0) { 
    @new-font-size: round(@base-font-size * pow(@base-scale-factor, @font-scale)); 
    font-size: @new-font-size; 
    line-height: ceil((@new-font-size/(@base-line-height * @base-font-size))) * (@base-line-height * @base-font-size); 
} 

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (isnumber(@margin-top)) { 
    margin-top: @base-font-size * (@base-line-height * @margin-top); 
} 

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (isnumber(@margin-bottom)) { 
    margin-bottom: @base-font-size * (@base-line-height * @margin-bottom); 
} 

用法:

p { 
    .rhythm(4, 1, 2); 
} 

輸出:

有人能幫助我的字體大小搞清楚這個問題?

回答

0

當我將它粘貼到codepen(http://codepen.io/anon/pen/wkFdc)中時,以下工作對我有用。

@base-font-size: 12px; 
@base-scale-factor: 2; 
@base-line-height: 12px; 

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (@font-scale > 0) { 
    @new-font-size: round(@base-font-size * pow(@base-scale-factor, @font-scale)); 
    font-size: @new-font-size; 
    line-height: ceil((@new-font-size/(@base-line-height * @base-font-size))) * (@base-line-height * @base-font-size); 
} 

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (@font-scale = 0) { 
    @new-font-size: round(@base-font-size * pow(@base-scale-factor, @font-scale)); 
    font-size: @new-font-size; 
    line-height: ceil((@new-font-size/(@base-line-height * @base-font-size))) * (@base-line-height * @base-font-size); 
} 

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (isnumber(@margin-top)) { 
    margin-top: @base-font-size * (@base-line-height * @margin-top); 
} 

.rhythm(@font-scale, @margin-top : false, @margin-bottom : false) 
when (isnumber(@margin-bottom)) { 
    margin-bottom: @base-font-size * (@base-line-height * @margin-bottom); 
} 

p { 
    .rhythm(4,1,2); 
} 

我所做的只是聲明瞭它上面的三個變量。你在哪裏宣佈他們的價值?如果它位於不同的文件中,請確保您在使用這些mixin之前導入該文件。

+0

奇怪的是,我一直在試圖編譯它使用lessphp和winless他們都給我錯誤.. :-) – Bogdan