这是我的问题。我正在使用小部件菜单。
我想向每个带有ACTIVE类的li:nth-child添加不同的CSS规则。
这是我的代码:
.wk-slideshow-default .nav .active
li:nth-child(1) span:hover {
width:19px;
height:18px;
background:url(/images/1r.png) !important;
overflow:hidden;
}
听起来很简单,对吧?好的,仅当我删除li:nth-child(1)时,此代码才有效。这是由于html的工作原理如下:
<ul class="nav">
<li></li>
<li></li>
<li class="active"></li>
<li></li>
<li></li>
</ul>
由于这是一个joomla扩展程序,因此我无法编辑HTML。
本质上,我想告诉CSS的是:
if you are li:nth-child(1) without the active class, change background to 1.jpg
if you are li:nth-child(1) WITH the active class, change background to 1r.jpg
if you are li:nth-child(2) without the active class, change background to 2.jpg
if you are li:nth-child(2) WITH the active class, change background to 2r.jpg
等等等等。 (没有活动类已经可以正常工作)
有什么办法可以像... li:nth-child(1,.active)吗?
最佳答案
您可以设置li.active:nth-child(1)
通过层次结构,您可以设置element[attribute].class:pseudo