我是靠谱客的博主 帅气超短裙,这篇文章主要介绍css3怎样实现选择表格的偶数行,现在分享给大家,希望可以做个参考。

本教程操作环境:windows10系统、CSS3&&HTML5版、Dell G3电脑。

css3怎样实现选择表格的偶数行

在css中,想要选择表格的偶数行元素,需要利用“nth-child()”选择器。

:nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型。

n 可以是数字、关键词或公式。

当选择器内的值是2n的时候,就会选择偶数个元素了。

示例如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<html> <head> <style> tr:nth-child(2n) { background:#ff0000; } </style> </head> <body> <table border="1"> <tr> <td>111</td> <td>222</td> </tr> <tr> <td>333</td> <td>444</td> </tr> <tr> <td>555</td> <td>666</td> </tr> <tr> <td>777</td> <td>888</td> </tr> <tr> <td>555</td> <td>666</td> </tr> <tr> <td>777</td> <td>888</td> </tr> </table> </body> </html>
登录后复制

输出结果:

19.png

(学习视频分享:css视频教程)

以上就是css3怎样实现选择表格的偶数行的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是帅气超短裙最近收集整理的关于css3怎样实现选择表格的偶数行的全部内容,更多相关css3怎样实现选择表格内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部