css - 如何使用 @include sass 做一些事情

标签 css sass

我不想使用 mixins 来定义我的属性。我想要在@extend/@include 之间构建一些东西,就像下面的例子

文件 => structure.scss

.box{
    width:100px;
    height:100px;
}

文件 => color.scss

@import 'structure.scss';
.box{
    @extend .box;
    background: red;
}

输出:

.box{
    width:100px;
    height:100px;
}
.box{
    background: red;
}

我不想要 mixins:

.box{
    width:100px;
    height:100px;
    background: red;
}

最佳答案

没有进口..

.bg-red {
    background: red;
}
.box {
    width:100px;
    height:100px;
    .bg-red;
}

.box {
    width:100px;
    height:100px;
}
.red-box {
    background: red;
    .box;
}

.square {
    width:100px;
    height:100px;
}
.bg-red {
    background: red;
}

.red-box {
    .square;
    .bg-red;
}

它仍然是一个mixin。顺便说一句,这是 LESS 语法,sass/scss 语法应该类似

或者只使用 OOCSS <div class="rounded red box"></div>

关于css - 如何使用 @include sass 做一些事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18293174/

相关文章:

HTML - Bootstrap 惊人的列

javascript - 解析 CSV,然后使用数据构建 Highcharts 条形图

npm 脚本的 SASS 问题( autoprefix 和 postcss )

html - 如何使背景图像适合所有屏幕尺寸?

css - 为什么 float 输入元素会改变它的高度?

css - Bootstrap - 水平对齐文本字段

css - 调用 SASS 内置函数的问题

javascript - 在哪里可以找到或覆盖 _navbar.scss?

css - 如何在模态填充中覆盖波旁风格?

css - SASS 工作流程,可通过 Grunt 更轻松地进行 CLI 调试