CSS scss 选择器中的 & 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38804099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 12:05:26 来源:igfitidea点击:
What does the & mean in an scss selector?
提问by Zhirayr
What does &
refer to in an scss selector?
什么是&
指在SCSS选择?
//Case 1 .parent { & > ul { color: red } } //Case 2 .parent { & > ul { & > li { color: blue; } } } //Case 3 .parent { & > ul { & > li { color: blue; &:hover { color: pink } } } }
回答by andreas
The &is a placeholder for the parent selector:
该&是父选择器的占位符:
.parent {
& > ul {
color: red
}
}
Is the same like
是不是一样
.parent > ul {
color: red
}
A common use case are pseudo classes, e.g.:
一个常见的用例是伪类,例如:
.link {
&:hover {
color: red
}
}
A nice explanation with examples can be found on CSS Tricks.
可以在CSS Tricks上找到带有示例的很好的解释。