我有一个Jquery方法,它添加了一个带有addClass()
的类,它假设在你单击div时添加一个名为“active
”的类。
它完美无缺,因为我可以在firebug中看到它确实添加了类名“active”。
<div class="rateWrapper L">
<div class="upV rateBtn">
</div>
<div class="numV largeFont">
5
</div>
<div class="dwnV rateBtn">
</div>
</div>
问题是,我看不到css的变化。
这是我的css:
.wrapper .tutVWrapper .rateWrapper .upV .rateBtn .active{ background:url('../img/up_V_active.png');}
.wrapper .tutVWrapper .rateWrapper .numV{ font-weight: bold; margin-bottom: 15px; margin-top: 15px; text-align: center;}
.wrapper .tutVWrapper .rateWrapper .dwnV{ background:url('../img/dwn_V_none.png'); width: 20px; height: 20px; cursor: pointer;}
.wrapper .tutVWrapper .rateWrapper .dwnV .rateBtn .active{ background:url('../img/dwn_V_active.png'); }
我该如何解决这个泡菜? 谢谢!
答案 0 :(得分:3)
我不知道您要将active
类添加到哪个元素,但从HTML中判断 - 还有rateBtn
作为类的元素。
您的CSS由.rateBtn .active
的空格分隔,使.active
仅适用于.rateBtn
的子元素。我想你想写.rateBtn.active
。
答案 1 :(得分:2)
如果两个类属于同一个元素,则类名之间的CSS规则中没有空格。空格意为“任何后代”。
所以例如.upv .rateBtn .active
应为.upv.rateBtn.active