1

如果有以下 HTML(可能有更多 TD),我可以在id="current" 之前的所有s 中选择所有divE<div>样式的 ALL 吗?TD

我想我可以用 jQuery 做到这一点,但这可以用纯 CSS 完成吗?

HTML

<table id="myTbl" cellpadding="0" cellspacing="0">
    <tr>
        <td>
          <div class="red">asdasd</div>
          <div class="divE"></div>
          <div class="divE"></div>
          content
        </td>
        <td id="current">
          <div class="red">asdasd</div>
          <div class="divE"></div>
          <div class="divE"></div>
          content
        </td>
        <td>
          <div class="red">asdasd</div>
          <div class="divE"></div>
          <div class="divE"></div>
          content
        </td>
    </tr>
</table>
4

1 回答 1

2

没有before选择器,但是您可以做的是选择所有tds(不是 s #current),然后“重置”(或“撤消”)所有tds after的样式#current

td:not(#current) div.divE{
    /* Styles for <td>s before "#current" */
}
td#current ~ td div.divE{ /* This means all "td div.divE" after "td#current" */
    /* Reset/undo styles for all other <td>s */
}

演示:http: //jsfiddle.net/MYhPP/2/

于 2012-05-04T22:20:29.180 回答