繁体   English   中英

较少的mixin返回Nanpx

[英]less mixin returning Nanpx

CSS Mixin

.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);
}

输出:

p {
  font-size: NaN;
  line-height: NaN;
  margin-top: 24;
  margin-bottom: 48;
}

有人可以帮我解决字体大小的问题吗?

当我将其粘贴到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);
}

我所做的就是声明其上方的三个变量。 您在哪里声明他们的价值观? 如果它在另一个文件中,请确保先导入具有这些mixins的文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM