覆盖列表样式

Mik*_*key 2 html css list css-selectors css-specificity

我有一个样式表用于ASP.Net站点中的多个CSS页面.其中两个页面的列表几乎完全相同.

例如

所有页面的样式:

li { padding-left:40px; text-indent:-44px; }
Run Code Online (Sandbox Code Playgroud)

列表样式需要单独的样式:

.customlistitem {padding-left:90px; text-indent:0px; }
Run Code Online (Sandbox Code Playgroud)

然后在实际页面中需要略有不同风格的列表:

<li class="customlistitem">
Run Code Online (Sandbox Code Playgroud)

问题是customlistitem选择器没有覆盖样式表中的样式.为什么是这样 ?

Jam*_*lly 6

看起来你需要增加选择器的特异性:

li.customlistitem {
    ...
}
Run Code Online (Sandbox Code Playgroud)

.customlistitem它本身确实具有更高的特异性li,所以我认为你的选择器比你在问题中包含的更复杂.无论如何,更高的特异性是要走的路.