【发布时间】:2016-02-10 05:07:51
【问题描述】:
我有多个 div::before 共享 90% 的样式,我想使用 SASS 的嵌套结构来设置它们的样式,以便仅指定差异,同时保持它们分组。但是当将成为& 的基础已经在使用伪元素时,我找不到该怎么做。这样做时:
SASS
#home .foo .bar::before {
content: "";
position: absolute;
margin: 2px;
background: url("images/baz.png") 0 0 no-repeat;
height: 39px;
width: 56px;
&.item-1 {
top: 0;
right: 0;
}
&.item-2 {
top: 10px;
right: 20px;
}
&.item-3 {
top: 40px;
right: 60px;
}
...
}
输出 CSS
#home .foo .bar::before {
content: "";
position: absolute;
margin: 2px;
background: url("images/baz.png") 0 0 no-repeat;
height: 39px;
width: 56px;
#home .foo .bar::before.item-1 {
top: 0;
right: 0;
}
#home .foo .bar::before.item-2 {
top: 10px;
right: 20px;
}
#home .foo .bar::before.item-3 {
top: 40px;
right: 60px;
}
...
当然,问题是 & 符号与 ::before 一起使用整个根,并在其末尾添加类 .item-x,因此 css 规则不起作用。我想要的输出是#home .foo .bar.item-2::before。我什至不确定是否可以这样嵌套,所以任何帮助都会很好。
感谢您的帮助!
【问题讨论】: