你见过这种css选择器吗?

时间:2010-09-30 06:54:36

标签: css css-selectors

table td+td+td+td+td+td{
    display:table-cell;
}

+是什么意思?

2 个答案:

答案 0 :(得分:4)

这是adjacent sibling selector

所以,如果你有......像:

<table> 
    <tr>
        <td></td> <!-- starting from here A-->
        <td></td> <!-- starting from here B-->
        <td></td>
        <td></td>
        <td></td>
        <td></td> <!-- selects this one A -->
        <td></td> <!-- selects this one B -->
    </tr>
</table>

因此将选择此示例中的最后两个单元格。见这里:http://jsfiddle.net/ERkEk/

整个CSS选择器似乎对我来说不是很有用(个人意见)就像对我硬编码一样。在某些情况下可能是必要的,但它比使用类更难维护。在这种情况下,你非常依赖标记。

更新: It is supported in all browsers but IE 5.5 and IE 6 and is not 100% supported in IE <= 8.

答案 1 :(得分:1)

相邻的兄弟选择器。

  

因此,以下规则规定当P元素紧跟在MATH元素后面时,它不应缩进:

math + p { text-indent: 0 } 

http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors