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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 04:39:35  来源:igfitidea点击:

Less first-child

cssless

提问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 .leftPanelis 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-childwith option:first-child.

您指定如果 a 中的第一个子元素.leftPanel是 a <select>,则它应该有margin-right: 30px;. 如果你正在尝试此规则适用于第一个子元素<select>(这应该永远是一个<option>),尝试更换&:first-childoption:first-child