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>
4

2 に答える 2

3

idを前に置く

#selected.level:first-child div:nth-child(1)  {
    background-position: 0px -429px;
    background-color:red
}
于 2012-07-24T17:45:33.680 に答える
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/

于 2012-07-24T17:52:57.463 に答える