2013-04-09 44 views
0

我有一個類rightband,它在message類的內部。有時候,父母<div class="message">有一個ID subnote,有時 - 沒有。代碼如下:使用:不刪除格式

<div class="message"> 
    <div class="rightband"> 
     <img id="img-up" src="arrow-up.png")" /> 
     <img id="img-down" src="arrow-down.png")" /> 
    </div> 
</div> 
<div id="subnode" class="message"> 
    <div class="rightband"> 
     <img id="img-up" src="arrow-up.png")" /> 
     <img id="img-down" src="arrow-down.png")" /> 
    </div> 
</div> 

在我的CSS,對於特殊原因我需要格式化改變懸停,而不是父類的子類rightband

#img-up, #img-down { 
    display: none; 
} 
#subnode .rightband:hover #img-up { 
    display: block; 
} 
:not(#subnode) .rightband:hover #img-down { 
    display: block; 
} 

.rightband:hover我需要顯示#img-up時,有父一個id =「subnode」,並顯示#img-down當父沒有subnode

這可以在CSS中完成,怎麼樣?

+0

FYI:ID應該是一個獨特的屬性。您應該將所有'img-up'和'img-down'的實例改爲class。 – 2013-04-17 21:39:33

回答

1

試着這麼做:

#img-up, #img-down { 
    display: none; 
} 
.rightband:hover #img-down { 
    display: block; 
} 
.rightband:hover #img-up { 
    display: none; 
} 

#subnode .rightband:hover #img-up { 
    display: block; 
}  
#subnode .rightband:hover #img-down { 
    display: none; 
} 
+0

謝謝,先生!像魅力一樣工作! – 2013-04-09 21:42:52