[英]CSS Not Selector for all children
I'm trying to apply a style to all li items as long as that item is not anywhere in a container with a class of .k-widget 我正在尝试对所有li项目应用一种样式,只要该项目不在带有.k-widget类的容器中的任何位置
.c-w1 ol li :not(.k-widget) { list-style: decimal outside; }
However the style continues to be applied. 但是,样式仍将继续应用。 The .k-widget is on a div that contain divs that contain the actual li I don't want styled.
.k-widget位于div上,该div包含我不想设置样式的实际li 。
<div class="k-widget">
<Lots of Things>
<li> ....
Should be something like that: 应该是这样的:
div:not(.k-widget) .c-w1 ol li {
list-style: decimal outside;
}
Of course the :not()
has to be applied on the div which is before the li as allready stated by Marijke Luttekes . 当然,
:not()
必须应用于由Marijke Luttekes声明的li之前的div上。
Also have a look at caniuse for browser support of css3 selectors . 也可以看看caniuse对浏览器对css3选择器的支持 。
Another possibility would be to tell the .k-widget
contents to inherit its styles with list-style: inherit;
另一种可能性是告诉
.k-widget
内容以list-style: inherit;
继承其样式list-style: inherit;
. 。 So you can override it without using a specific value and adding redundance to your styles:
因此,您可以在不使用特定值的情况下覆盖它,并在样式中添加冗余:
div .c-w1 ol li {
list-style: decimal outside;
}
div.k-widget .c-w1 ol li {
list-style: inherit;
}
Currently the list style is applied to any item inside a li
that does not have the class .k-widget
applied. 当前,列表样式将应用于
li
中没有应用.k-widget
类的任何项目。 If I understand your problem correctly, you can easily fix this by placing the statement :not(.k-widget)
before li
. 如果我正确理解了您的问题,则可以通过在
li
之前放置语句:not(.k-widget)
来轻松解决此问题。
The problem is that the :not()
selector on a parent will match if any parent matches, and since all li
elements are within both body
and html
, all li
elements will match. 问题是,如果有任何父项匹配,则父项上的
:not()
选择器将匹配,并且由于所有li
元素都在body
和html
,因此所有li
元素都将匹配。
I would recommend constructing two styles, one overriding the other. 我建议构造两种样式,一种覆盖另一种样式。
.c-w1 ol li { list-style: decimal outside; }
And 和
.c-w1 .k-widget ol li { override style here }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.