【发布时间】:2013-11-02 10:18:12
【问题描述】:
@extend 的一个常见问题是尝试用另一个 @extend 覆盖继承的属性时。
这是一个例子:
// class selectors to be @extended
// these could also use % to be silent/placeholder selectors
.size-2xl {
@include rem(font-size, 40px);
}
.size-3xl {
@include rem(font-size, 60px);
}
// mapping the class selector properties onto some structural classes
.heading1 {
@extend .size-3xl;
}
.heading1-small {
@extend .heading1;
@extend .size-2xl;
}
编译 SCSS 时,.heading1 和 .heading1-small 将获得正确的属性,但 .heading1-small 会显得太大。
当@extend-able 类映射到几个不同的选择器时,这似乎会发生。
SCSS 编译成 CSS 时,各种选择器组合成一个或多个带有多个选择器的规则集。
有时 SCSS 似乎被“乱序”编译,因此编译后的 .heading1 多重选择器在 .heading1-small 多重选择器之后输出。
甚至可能是嵌套的@extend 导致了这种行为。
避免这种情况的最佳方法是什么?我能想到的一些事情是:
- 使用
@include('size-2xl')(少干) - 不要在
@extend规则中包含@extend(限制@extend 的使用)
谢谢。
【问题讨论】:
标签: sass compass-sass