css查找表格第几行几列
说明:利用ntn-child(n)选择器进行实现。其中n代表选择元素中的第几个元素,第几个就写几,特殊的,要选中第一个可以写为:
first-child ,要选中最后一个可写为,last-child,要选择偶数个,可写为nth-child(2n),同理,奇数列可写为nth-child(2n+1),这不仅适用于table的列,也适合于所有选中的元素。
核心代码:table tr:nth-child(n) td:nth-child(n),第一个n选中第n行,第2个n选中第n列。
/* 这里选中了第2行,第1列,将它背景设置为红色 */
table tr:nth-child(2) td:nth-child(1){
background-color: red;
}