css - LESS 使用伪选择器添加类

标签 css less

我使用 LESS,这是我的例子:

.arrow{
   color: red;
}
.arrow:before{
   content: ">";
}

.button{
  background: blue;
  .arrow;
  &:before{
    border: 1px solid;
  }
}

这是解析后的 CSS:

.button{
   background: blue;
   color: red;
}
.button:before{
   border: 1px solid; // HERE IS NO  content: ">" !!!
}

如何将 .arrow 类中的 :before 伪元素添加到我的按钮?

最佳答案

您可以使用 extend 选项,如下所示。它基本上也将 arrow 类的所有属性应用于 button 类。 all 关键字表示子类也被扩展。

减少:

.button{
    background: blue;
    &:extend(.arrow all);
    &:before{
        border: 1px solid;
    }
}

编译后的 CSS:

.arrow,
.button {
    color: red;
}
.arrow:before,
.button:before {
    content: ">";
}

关于css - LESS 使用伪选择器添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25359285/

相关文章:

html - 如何在网站中进行动态填充

javascript - css 属性未正确应用 [底部,右侧]

css - LESS - 在嵌套 Mixin 上使用防护

css - less mixin 不继承类

visual-studio-2012 - Web Essentials v2.8 LESS导入错误

css - JavaFX 和 CSS RadioButton 样式

css - 预加载器图像动画未居中

html - 为图像上的文本提供背景阴影

css - 使用数据 URI 而不是 Sprite 图像有什么缺点?

css - 可缩放字体大小,SASS (LESS) with "px"vs plain ems