[英]Applying CSS styles to <li> in an ordered list without applying to a nested ol
I have a nested ordered list with this structure 我有一个具有此结构的嵌套有序列表
<ol>
<li>
<span>A</span>
<ol class="childol">
<li>
<span>A1</span>
</li>
<li>
<span>A2</span>
</li>
</ol>
</li>
</ol>
I'm trying to apply a style to the li, eg a background colour: 我正在尝试将样式应用于li,例如背景颜色:
li:nth-child(1) { background-color: hsla(41, 100%, 93%, 1); }
and I get this: 我明白了
I'm trying to get the "Introduction to Lists" highlighted on its own with 100% width. 我试图以100%宽度突出显示“列表简介”。 I've tried to exclude the child ol like this:
我试图像这样排除孩子:
li:nth-child(1) :not(.olchild) { background-color: hsla(41, 100%, 93%, 1); }
but I just get this: 但我得到这个:
How do I do this? 我该怎么做呢?
jsfiddle: http://jsfiddle.net/koesbong/KRv4v/3/ jsfiddle: http : //jsfiddle.net/koesbong/KRv4v/3/
ol li {background-color: red;}
ol li li {background-color: white;}
or 要么
ol:not(.childol) > li {background-color: red;}
ol li {background-color: white;}
use this 用这个
ol li{
background:yellow;
}
li ol li{
background:green;
}
只需使用儿童组合器( ol > li
)而不是后代组合( ol li
)。
The problem is the backgournd colour is applied to the whole of the first list item of your parent list. 问题是backgournd颜色应用于父列表的整个第一个列表项。 I'd applie a class to the parent list and style that:
我将一个类应用于父列表和样式:
<style>
ol.parent>li{ background-color: hsla(41, 100%, 93%, 1); }
li>ol, li>ol>li{background-color:#FFF;}
</style>
<ol class="parent">
<li>
<span>A</span>
<ol>
<li>
<span>A1</span>
</li>
<li>
<span>A2</span>
</li>
</ol>
</li>
</ol>
Replacing White (#FFF) with your appropriate background colour 用适当的背景颜色替换白色(#FFF)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.