css - 如何使用 .less 在按钮上组合类?

标签 css less

我有这个按钮的 .less 文件:

 button {
        background: @button-background;
        color: @text;

        &.primary {
            background-image: linear-gradient(#79d858, #569e3d);
            border-color: #4a993e;
            color: white;
        }

        &.primary:hover {
            background-image: linear-gradient(#89e868, #66ae4d);
            border-color: #4a993e;
            color: white;
        }

        &.primary:active,
        &.primary:focus {
            background-image: linear-gradient(#99f878, #76be5d);
            border-color: #4a993e;
            color: white;
        }

    }

有人可以就如何将所有 &.primary 合并为一个提供建议吗?

最佳答案

这是你想要的吗:

button {
    background: @button-background;
    color: @text;

    &.primary {
        background-image: linear-gradient(#79d858, #569e3d);
        border-color: #4a993e;
        color: white;

        &:hover {
            background-image: linear-gradient(#89e868, #66ae4d);
        }

        &:active, &:focus {
            background-image: linear-gradient(#99f878, #76be5d);
        }
    }
}

DEMO

关于css - 如何使用 .less 在按钮上组合类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29839086/

相关文章:

javascript - 在 div 内动态创建最大宽度/适合的三 Angular 形

c# - Bundle Transformer for LESS 和 @import 的使用

css - 在 LESS css 中有条件地声明变量

css - 使用 CSS :not selector in LESS nested rules

sass - LESS、SASS 和 STYLUS 中常用的符号 (&) 的 POSTCSS 等价物是什么?

css - 如何创建一个需要在一个元素中使用多个类的 CSS 选择器?

css - 如何使用纯CSS来显示一个元素的背景和颜色属性的动画?

jquery - 图层 slider 导航位置

javascript - 如何设置一个元素一个接一个显示的持续时间

css - 页脚没有响应