2012-06-23 45 views
2

我有一個jQuery的方法,添加一個類addClass(),它假設添加一個名爲「active」類,當你點擊div。addClass添加了一個類,但不會改變它的CSS?

它完美地工作,因爲我可以在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'); } 

我怎麼能解決這個鹹菜? 謝謝!

回答

2

如果兩個類屬於同一個元素,那麼在類名之間的CSS規則中就沒有空間。空間意味着「任何後裔」。

所以例如.upv .rateBtn .active應該.upv.rateBtn.active

+0

謝謝你,你釘它:) – thormayer

3

我不知道你要添加哪個元素active類,但是從你的HTML判斷 - 到也有rateBtn作爲類的元素。

您的CSS被空格分隔爲.rateBtn .active,因此.active僅適用於.rateBtn的子元素。我想你想寫.rateBtn.active

+0

謝謝你,戶田拉巴:) – thormayer

+0

@thormayer:大聲笑,bevaksha :) –

相關問題