首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cassette Sass编译在CSS中生成空值

Cassette Sass编译在CSS中生成空值
EN

Stack Overflow用户
提问于 2013-11-15 20:11:05
回答 2查看 269关注 0票数 0

到目前为止,我们已经有了一个构建后步骤,在命令行上使用Sass gem来生成我们的global.css。

我换成了Cassette,它使用的是Cassette.Sass,它使用的是SassAndCoffee,显然使用的是Sass 3.2.0 :-)

然而,当Cassette进行编译时,我在生成的css中得到了奇怪的空值。从页面的外观来看,这是无效的css并搞砸了设计。

例如:

代码语言:javascript
复制
.pure-container {
padding: 31px null;
padding: 1.714rem null;
padding-right: 0.9375%; }

我认为这可能是由于Sass的版本差异(因为我们使用的是3.2.8版本的sass gem ),但如果我从命令行使用Sass gem版本3.2.0,我得到的输出与开始使用Cassette之前相同(有效),没有null值:

代码语言:javascript
复制
.pure-container {
padding: 31px;
padding: 1.71429 rem;
padding-right: 0.9375%; }

所以总而言之,使用SASS3.2.0的Cassette.Sass编译我的CSS的方式与从命令行编译SASS3.2.0Gem的方式不同。我应该检查什么?

我不是前端开发人员,对scss也不是很熟悉,但如果与之相关,下面是我们的global.scss的样子:

代码语言:javascript
复制
// ----- SCSS Helpers -----
@import "imports/_mixins.scss";
@import "imports/_variables.scss";

// ----- Pure Grid -----
@import "imports/_extend-pure.scss";

// ----- Theme -----
@import "imports/_typography.scss";
@import "imports/_helpers.scss";
@import "imports/_buttons.scss";
@import "imports/_forms.scss";
@import "imports/_modules.scss";


// ----- Media Queries -----
@import "imports/_media-phone.scss";
@import "imports/_media-tablet-query.scss";
@import "imports/_media-desktop-query.scss";

并且所有这些导入的文件都存在,并且没有SASS编译异常。

我能找到的唯一提到'null‘的地方是在_mixins.scss中:

代码语言:javascript
复制
@mixin size($property: null, $units: 4, $importance: null, $mixin: null) {
  // This mixin will calculate the rem values defined by design (6px's in mobile and scaled up for desktop)
  // Because IE8 and below don't support rem, we insert the px equivalent for the desktop sizes just before.
  $pixel-size: round(((6*$units)*((1/$font-size-mobile)*$font-size-desktop))) + px $importance;
  $rem-size: ((1/$font-size-mobile)*(6*$units)) + rem $importance;
  @if $mixin == min-height {
    @include min-height($pixel-size);
    @include min-height($rem-size);
  }
  @else if $mixin == max-height {
    @include max-height($pixel-size);
    @include max-height($rem-size);
  }
  @else {
    #{$property}: $pixel-size; // This number is rounded to the nearest whole number to avoid issues with IE7
    #{$property}: $rem-size;
  }
  // EXAMPLE OF HOW TO USE
  // @include size(line-height, 4, !important); <-- important is optional
  // EXAMPLE OF HOW TO USE 2
  // @include size($mixin: min-height, $units: 4);
}

Cassette在其他方面非常棒,我很想使用它,但这是一个相当大的障碍!任何想法都值得感谢,包括我还可以在哪里发布这篇文章,希望能得到一个可能有所帮助的答案!我知道还有其他的选择来编译Sass,如果我在这里得不到太多的乐趣,我会抛弃磁带,支持MS.Web.Optimization和NSass的组合,但我真的想让磁带工作,如果我可以的话!

谢谢,马克。

EN

回答 2

Stack Overflow用户

发布于 2013-11-19 01:44:35

null来自默认值$importance。

将其放在if语句中,并仅在值不是默认null时应用它。

谢谢

代码语言:javascript
复制
@mixin size($property: null, $units: 4, $importance: null, $mixin: null) {
  // This mixin will calculate the rem values defined by design (6px's in mobile and scaled up for desktop)
  // Because IE8 and below don't support rem, we insert the px equivalent for the desktop sizes just before.
  $pixel-val: round(((6*$units)*((1/$font-size-mobile)*$font-size-desktop)));
  $rem-val: ((1/$font-size-mobile)*(6*$units));
  @if $importance == null {
      $pixel-size: $pixel-val + px;
      $rem-size: $rem-val + rem;
  } @else {
      $pixel-size: $pixel-val + px $importance;
      $rem-size: $rem-val + rem $importance;
  }

  @if $mixin == min-height {
    @include min-height($pixel-size);
    @include min-height($rem-size);
  } @else if $mixin == max-height {
    @include max-height($pixel-size);
    @include max-height($rem-size);
  } @else {
    #{$property}: $pixel-size; // This number is rounded to the nearest whole number to avoid issues with IE7
    #{$property}: $rem-size;
  }
  // EXAMPLE OF HOW TO USE
  // @include size(line-height, 4, !important); <-- important is optional
  // EXAMPLE OF HOW TO USE 2
  // @include size($mixin: min-height, $units: 4);
}
票数 0
EN

Stack Overflow用户

发布于 2013-11-21 08:39:14

我试图构建上面的解决方案,但我遇到了错误。似乎在if语句中设置变量会使这些变量保持私有。

这是另一个带有注释的解决方案

代码语言:javascript
复制
@mixin size($property: null, $units: 4, $importance: false, $mixin: null) { // change default value of importance to false
  $pixel-size: round(((6*$units)*((1/$font-size-mobile)*$font-size-desktop))) + px;
  $rem-size: ((1/$font-size-mobile)*(6*$units)) + rem; // remove importance from here
  @if $mixin == min-height {
    @include min-height($pixel-size);
    @include min-height($rem-size);
  }
  @else if $mixin == max-height {
    @include max-height($pixel-size);
    @include max-height($rem-size);
  }
  @else {
    @if $importance { // do the test here
        #{$property}: $pixel-size $importance;
        #{$property}: $rem-size $importance;
    } @else {
        #{$property}: $pixel-size;
        #{$property}: $rem-size;        
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20000797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档