如何select第一个child第一个兄妹阿莉?

how to select the first child of the first siblings of a li?

我想 select 从我的 css select 或

中取出嵌套的 li

Demo

li:first-child {
    background-color: rgb(236, 236, 236);
    list-style-type: none;
    margin-bottom: 3px;
    padding: 8px;
}
<ul>
    <li>to be selected</li>
    <li></li>
    <li>
        <ul>
           <li>not to be selected</li>
           <li></li>
           <li></li>
        </ul>
    </li>
        
</ul>

无论第一个 ul 的父级是什么,然后 >(这意味着直系子级,了解更多信息 here)。像这样。

body > ul > li:first-child {
    background-color: rgb(236, 236, 236);
    list-style-type: none;
    margin-bottom: 3px;
    padding: 8px;
}
<ul>
    <li>to be selected</li>
    <li></li>
    <li>
        <ul>
            <li>not to be selected</li>
            <li></li>
            <li></li>
        </ul>
    </li>
</ul>

您可以设置样式,然后撤消它们。

li:first-child {
    background-color: rgb(236, 236, 236);
    list-style-type: none;
    margin-bottom: 3px;
    padding: 8px;
}

li li:first-child {
    background-color: inherit;
    list-style-type: inherit;
    margin-bottom: inherit;
    padding: inherit;
}

Fiddle; https://jsfiddle.net/wLspzcho/

我不知道这是不是你想要的,但试试这个

.first > li:first-child {
    background-color: rgb(236, 236, 236);
    list-style-type: none;
    margin-bottom: 3px;
    padding: 8px;
}
<ul class="first">
    <li>to be selected</li>
    <li></li>
    <li>
        <ul>
           <li>not to be selected</li>
           <li></li>
           <li></li>
        </ul>
    </li>
        
</ul>