css - Sass 混合编译错误

标签 css sass

<分区>

所以我试图将这个人字形代码应用到一个 sass mixin 中: http://lugolabs.com/caret .

但是我遇到了 sass 编译错误。

表示这一行:“border-$dira: $secondSize solid $bgColor;” 不正确...

有人能告诉我这段代码有什么问题吗?

@mixin chevron($caretWidth, $borderWidth, $direction: 'top', $color, $bgColor) {

  @if $direction == 'top' { 
    $dira: 'bottom';
    $dirb: 'left';
    $dirc: 'right';
    $top1:0px;
    $left1:0px;
    $top2:$borderWidth;
    $left2:$borderWidth;

  } @else if $direction == 'bottom' {
    $dira: 'top';
    $dirb: 'left';
    $dirc: 'right';
    $top1:0px;
    $left1:0px;
    $top2:0px;
    $left2:$borderWidth;
  } @else if $direction == 'left' {
    $dira: 'right';
    $dirb: 'top';
    $dirc: 'bottom';
    $top1:0px;
    $left1:0px;
    $top2:$borderWidth;
    $left2:$borderWidth;
  } @else if $direction == 'right' {
    $dira: 'left';
    $dirb: 'top';
    $dirc: 'bottom';
    $top1:0px;
    $left1:0px;
    $top2:$borderWidth;
    $left2:0px;
  }

  position: relative;

  $secondSize: $caretWidth - $borderWidth;

  &:before {
    content: '';
    position: absolute;
    top: $top1;
    left: $left1;
    border-$dira: $caretWidth solid $color;
    border-$dirb: $caretWidth solid transparent;
    border-$dirc: $caretWidth solid transparent;
  }

  &:after {
    content: '';
    position: absolute;
    top: $top2;
    left: $left2;
    border-$dira: $secondSize solid $bgColor;
    border-$dirb: $secondSize solid transparent;
    border-$dirc: $secondSize solid transparent;
  }
}

最佳答案

为了使 SASS 在输出本身中正确打印字符串,请使用 SASS 提供的字符串插值方法:#{$do-what-ever}

文档:http://sass-lang.com/documentation/file.SASS_REFERENCE.html#interpolation_

@mixin chevron($caretWidth, $borderWidth, $direction: 'top', $color, $bgColor) {

  @if $direction == 'top' { 
    $dira: 'bottom';
    $dirb: 'left';
    $dirc: 'right';
    $top1:0px;
    $left1:0px;
    $top2:$borderWidth;
    $left2:$borderWidth;

  } @else if $direction == 'bottom' {
    $dira: 'top';
    $dirb: 'left';
    $dirc: 'right';
    $top1:0px;
    $left1:0px;
    $top2:0px;
    $left2:$borderWidth;
  } @else if $direction == 'left' {
    $dira: 'right';
    $dirb: 'top';
    $dirc: 'bottom';
    $top1:0px;
    $left1:0px;
    $top2:$borderWidth;
    $left2:$borderWidth;
  } @else if $direction == 'right' {
    $dira: 'left';
    $dirb: 'top';
    $dirc: 'bottom';
    $top1:0px;
    $left1:0px;
    $top2:$borderWidth;
    $left2:0px;
  }

  position: relative;

  $secondSize: $caretWidth - $borderWidth;

  &:before {
    content: '';
    position: absolute;
    top: $top1;
    left: $left1;
    border-#{$dira}: $caretWidth solid $color;
    border-#{$dirb}: $caretWidth solid transparent;
    border-#{$dirc}: $caretWidth solid transparent;
  }

  &:after {
    content: '';
    position: absolute;
    top: $top2;
    left: $left2;
    border-#{$dira}: $secondSize solid $bgColor;
    border-#{$dirb}: $secondSize solid transparent;
    border-#{$dirc}: $secondSize solid transparent;
  }
}

关于css - Sass 混合编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34928092/

上一篇:html - 如何在 Rails 4.2.4 中设计一个带有十六进制颜色的 Twitter Bootstrap 按钮

下一篇:javascript - 在窗口中居中动态生成的表格单元格

相关文章:

css - 用scss知道类是否存在

jquery - Bootstrap : Collapse others when one is expanded

html - 表格 float 和文本框问题

javascript - 使用保存的密码使输入元素内的标签消失

html - CSS/ Safari : Div box with float and percentage width is not 100% aligned

css - 动画关键帧的 scss 函数

html - 使用本地样式表规范化 CSS 显示不正确

css - 萨斯 : overwrite definitions with different placeholder in @media query

html - 在 Angular 中转换 CSS 类?

css - Sass/Css 我可以在悬停 Action 中设置多个类吗?