CSS 少第一个孩子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11775300/
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
Less first-child
提问by Rhyso
Why isn't my first-child selector working in Less?
为什么我的第一个孩子选择器不能在 Less 中工作?
.leftPanel{
margin:20px;
float:left;
display:inline;
width:620px;
margin-left:10px;
select{
width:300px;
&:first-child{
margin-right: 30px;
}
}
}
采纳答案by Kaivosukeltaja
You are specifying that if the first child element inside a .leftPanel
is a <select>
, it should have margin-right: 30px;
. If you are trying to apply this rule to the first child element insidethe <select>
(which should always be an <option>
), try replacing &:first-child
with option:first-child
.
您指定如果 a 中的第一个子元素.leftPanel
是 a <select>
,则它应该有margin-right: 30px;
. 如果你正在尝试此规则适用于第一个子元素内的<select>
(这应该永远是一个<option>
),尝试更换&:first-child
用option:first-child
。