我用:
.first{
.second{
.third{
.between_second_and_third & {
/* some rules */
}
}
}
}
最后我有:
.between_second_and_third .first .second .third {/* some rules */}
但我想:
.first .second .between_second_and_third .third {/* some rules */}
我该怎么做?
答案 0 :(得分:2)
首先,&
标记引用当前的父选择器(如提到here)
这就是为什么你得到这个最终陈述,因为你定义了类似的东西:
.first{
.second{
.third{
.between_second_and_third .first .second .third {
/* some rules */
}
}
}
您只需要在between_second_and_third
和.second
类声明之间嵌套.third
类,如下所示:
.first{
/* first rules */
.second{
/* rules for second */
.between_second_and_third {
/* rules between */
.third{
/* some other rules */
}
}
}
此声明呈现这行CSS代码:
.first { /* first rules */ }
.first .second { /* rules for second */ }
.first .second .between_second_and_third {/* rules between */}
.first .second .between_second_and_third .third {/* some other rules */}