CSS3伪类nth-of-type(n)用法详解
来源:互联网 发布:房屋框架设计软件 编辑:程序博客网 时间:2024/05/01 07:57
CSS3中nth-of-type(n)(比如nth-of-type(1))这个特殊的类选择符可以样式更加个性的标题和段落等,不过,目前nth-of-type(n)只支持火狐3、opera、safari和chrome等部分浏览器。
如下代码:
如下代码:
.comments-template ol li:nth-of-type(odd){background:#DBF1D4;}
上面的代码是指,将列表的偶数(odd)列的背景颜色设置为:#DBF1D4,如果初始化时定义列表背景颜色,就可以产生背景颜色交替变化的列表。
除了可以将n设置为odd(偶数)或even(奇数)外,还可以将n设置为表达式,比如,
nth-of-type(3n+2)
上述代码中,设n=0、1、2……,则3n+2等于2、5、8……,也就是仅样式2、5、8……所代表的元素。
nth-of-type(n)应用举例
如下192.168.1.1所在的2、5、8行的背景颜色为#9966cc
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
关于CSS伪类
CSS 伪类用于向某些选择器添加特殊的效果。
比如常见的锚伪类:
a:link {color: #FF0000}
a:visited {color: #00FF00}
a:hover {color: #FF00FF}
a:active {color: #0000FF}
html源代码为:
<ulid=“nth”>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
<li>192.168.1.1</li>
</ul>
CSS源代码为:
ul#nthli:nth-of-type(3n+2)
background:#DBF1D4;
当然,完全可以使用相同的方法来样式h2标题和p段落等。
0 0
- CSS3伪类nth-of-type(n)用法详解
- css选择器中:first-child与:first-of-type的区别///CSS3伪类nth-of-type(n)用法详解
- 【CSS3】nth-of-type(n)选择器
- 【CSS3】nth-last-of-type(n)选择器
- css 伪类选择器 :nth-child(n) 与:nth-of-type(n)的区别
- CSS3伪类选择器nth-child和nth-of-type浅析
- 【CSS3】---first-of-type选择器+nth-of-type(n)选择器
- 伪类选择器之结构选择器::noth-child(n)/:nth-of-type(n)
- CSS3 :nth-child() 与:nth-of-type()
- 【CSS3】---last-of-type选择器+nth-last-of-type(n)选择器
- 【CSS3】结构性伪类选择器—nth-child(n)
- 【CSS3】结构性伪类选择器—nth-last-child(n)
- CSS3中nth-of-type和nth-last-of-type
- nth-of-type(n)选择器
- CSS3 伪类nth-child
- CSS3 :nth-child() ,nth-of-type(),nth-last-child() ,nth-last-of-type()
- CSS3选择器之:nth-child()伪类选择器详解
- CSS3选择器之nth-of-type
- Android内存泄漏分析及调试
- Unhandled exception type SQLException 异常
- 【 D3.js 入门系列 --- 4 】 如何使用scale(比例)
- mac There are no interface on Which a capture can be done
- 10大基础实用算法
- CSS3伪类nth-of-type(n)用法详解
- QML元素介绍
- SEO优化要以“大局为重”
- git发邮件
- linux下mnt目录作用
- 75_leetcode_Covert Sorted List to Binary Tree
- jquery对ajax的支持
- Hive学习之函数DDL和Show、Describe语句
- C标准IO缓存长度限制0124