CSS3选择器
2015-08-06 16:10
459 查看
注意:IE8及之前版本不支持
使用:nth-of-type给表格行设置条纹
tr:nth-of-type(even){background-color:#ddd;}
//设置偶数行背景色
tr:nth-of-type(odd){background-color:#ddd;}
//设置奇数行背景色
使用:nth-child对齐表格列的内容
公式:nth-child(an+b)
//a是倍数,n是从0开始计数,b是偏移量
table tr:nth-child(n)
//选择表格所有行
table tr:nth-child(n+2)
//选择表格除第一行的所有行
table tr:nth-child(2n)
//隔行选择表格行
table tr:nth-child(3n)
//隔两行选择一行
table tr:nth-child(2n+4)
//从第四行开始的相隔行
举例:
td:nth-child(n+2),th:nth-child(n+2){text-align:right;}
//除去第一行和第一列,向右对齐
另:nth-last-child为反向遍历元素,以最后一个子元素为起点,比如获取倒数第二行可以使用tr:nth-last-child(2){...},选择最后三行可以使用tr:nth-last-child(-n+3){...}
使用:last-child选择最后一个元素
tr:last-child td:last-child{font-size:24px;}
//选择表格的最后一行的最后一列
使用after和content生成友好的打印链接
a:after{content:"(" attr(href) ")"};
//只在打印文本时有效,在a标签后面追加显示跳转的链接
使用:nth-of-type给表格行设置条纹
tr:nth-of-type(even){background-color:#ddd;}
//设置偶数行背景色
tr:nth-of-type(odd){background-color:#ddd;}
//设置奇数行背景色
使用:nth-child对齐表格列的内容
公式:nth-child(an+b)
//a是倍数,n是从0开始计数,b是偏移量
table tr:nth-child(n)
//选择表格所有行
table tr:nth-child(n+2)
//选择表格除第一行的所有行
table tr:nth-child(2n)
//隔行选择表格行
table tr:nth-child(3n)
//隔两行选择一行
table tr:nth-child(2n+4)
//从第四行开始的相隔行
举例:
td:nth-child(n+2),th:nth-child(n+2){text-align:right;}
//除去第一行和第一列,向右对齐
另:nth-last-child为反向遍历元素,以最后一个子元素为起点,比如获取倒数第二行可以使用tr:nth-last-child(2){...},选择最后三行可以使用tr:nth-last-child(-n+3){...}
使用:last-child选择最后一个元素
tr:last-child td:last-child{font-size:24px;}
//选择表格的最后一行的最后一列
使用after和content生成友好的打印链接
a:after{content:"(" attr(href) ")"};
//只在打印文本时有效,在a标签后面追加显示跳转的链接
相关文章推荐
- 修改element.style样式
- cursor样式
- css display属性
- css3滚动条动画
- CSS自定义字体
- CSS HACK技巧
- 经典下拉式菜单 js+css 实现
- CSS3属性选择器
- CSS3实现3D六面体
- 理解CSS3 transform中的Matrix(矩阵)
- css3新特性1——文本效果&边框&背景&多列
- CSS定位
- css区分ie6,7,ff
- css用法大全
- 使用CSS3画出一个叮当猫
- CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)
- WPF Button 鼠标移动改变样式
- 解决C# winForm自定义鼠标样式的两种实现方法详解
- 201508061158_《移动开发之——样式链表》
- 纯CSS3画出小黄人并实现动画效果