Sass’s behavior for declarations that appear after nested rules will be changing to match the behavior specified by CSS in an up
Sass版本更新与声明规范变化
Sass即将对嵌套规则后的声明规范做出调整,以更好地匹配CSS规范。这意味着在Sass的新版本中,如果在嵌套规则后放置声明,其声明规范将有所变化。
1. 保持现有规范
为了保持Sass当前(旧)的规则,即将嵌套规则后的声明移动到嵌套规则之前。例如:
// 旧版Sass代码
.parent {
color: blue;
.child {
font-size: 12px;
}
margin: 10px; // 此声明将受到影响
}
// 修改后的代码以保持旧规范
.parent {
color: blue;
margin: 10px; // 移动到嵌套规则之前
.child {
font-size: 12px;
}
}
2. 选择新的规范
想采用Sass新版本中的规范变化,可以将受影响的声明包裹在& {}
中。例如:
.parent {
color: blue;
.child {
font-size: 12px;
}
& {
margin: 10px; // 使用& {}包裹
}
}
注意,使用& {}
包裹的声明将不会受到嵌套层级的影响,它们将被视为与.parent
选择器在同一层级。
总结
- 将声明移动到嵌套规则之前
- 使用
& {}
来包裹嵌套规则后的声明