2012-07-24 173 views
0

我有一個班級分配給第一個div與類「級」的div。工作正常。選擇嵌套元素

如果父div具有id =「selected」,我需要交換樣式。有困難的選擇吧...

.level:first-child div:nth-child(1) { 
    background-position: 0px -368px; 
} 
.level:first-child div:nth-child(1) #selected { 
    background-position: 0px -429px; 
    background-color:red 
} 
<div class="level" id="selected"> 
    <div></div> 
    <div></div> 
</div> 

回答

3

id

#selected.level:first-child div:nth-child(1) { 
    background-position: 0px -429px; 
    background-color:red 
} 
+0

Dah ...嘗試了一切,但明顯...謝謝! – santa 2012-07-24 17:47:00

+0

不客氣。 – 2012-07-24 17:48:34

1

試試這個:

.level:first-child div:nth-child(1) { 
    background-position: 0px -368px; 
} 
.level:first-child#selected div:nth-child(1) { 
    background-position: 0px -429px; 
    background-color:red 
}​ 

例如:http://jsfiddle.net/HARWp/1/