css - Less guard 不处理 mixin 的多个参数

标签 css less web-frontend

我已经在互联网上搜索并尝试了多种代码,但无法弄清楚这个。希望您能助一臂之力。

问题:当 mixin 有多个值时,Guard 不会被触发。

无按钮

  /* CTA Box */
  &ctabox {
    .inline-box(@lightergrey);

    &__header {
      display: inline-block;
      margin: 5px 0;
      .font(@size: 18px, @weight: 700);
    }

    &__button {
      .button(@style: @orange);
      .button-icon-right();
    }

  }

如你所见,我使用了 button() 混合,@style: @orange 起作用并触发了这个守卫:

.button(@style) when (@style = @orange) {
  /* Rendered mixin: Button @style when @orange */
  color: #FFF;

  &:hover, &:focus {
    background: @lightorange;
    color: #FFF;
  }

}

但是当我使用这个时:

&__button {
  .button(@style: @orange, @width: 100%);
  .button-icon-right();
}

虽然按钮@style 仍然是@orange,但守卫不再被触发。 谁能解释这种行为?

最佳答案

好的,经过一番挖掘,似乎提及混合函数的所有参数是可行的方法。我将它改为 .button(@style, @width) 而不是仅仅 .button(@style) 并且 guard 现在正常运行。

.button(@style, @width) when (@style = @orange) {
  /* Rendered mixin: Button @style when @orange */
  color: #FFF;

  &:hover, &:focus {
    background: @lightorange;
    color: #FFF;
  }

}

关于css - Less guard 不处理 mixin 的多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41148086/

相关文章:

javascript - 调整元素大小,使其与不滚动所需的高度完全一样

background-color - 具有圆 Angular 和重叠背景颜色的 CSS 选择

netbeans - 无法在 Netbeans 7.4 上添加 less-compiler lessc

html - 将搜索栏与导航中的其他元素对齐

css - 带有搜索框的导航栏 - MaterializeCss

html - CSS/HTML : Dynamic `hat` border on hover of menu item

jquery - 如何将同位素容器内的元素居中?

css - 使用 LESS 进行 CSS 渲染会破坏基于浏览器的开发吗?

css - 较少循环遍历数组会不断附加先前的值

javascript - 编码问题,无法用 API 元素创建数组,Reactjs