nth用法:1、“:nth-child(n)”匹配第n个子元素;2、“:nth-last-child(n)”倒数匹配第n个子元素;3、“:nth-of-type(n)”匹配同类第n个子元素;4、“:nth-last-of-type(n)”。

本教程操作环境:windows10系统、CSS3&&HTML5版本、Dell G3电脑。
css中nth的用法是什么
1、:nth-child(n)
:nth-child(n) 选择器匹配父元素中的第 n 个子元素,元素类型没有限制。
n 可以是一个数字,一个关键字,或者一个公式。
立即学习“前端免费学习笔记(深入)”;
示例如下:
123 这是一个标题
这是第一个段落。
这是第二个段落。
这是第三个段落。
这是第四个段落。
注意: Internet Explorer 8 以及更早版本的浏览器不支持 :nth-child()选择器.
输出结果:

2、:nth-last-child(n)
:nth-last-child(n) 选择器匹配属于其元素的第 N 个子元素的每个元素,不论元素的类型,从最后一个子元素开始计数。
n可以是一个数字,一个关键字,或者一个公式。
示例如下:
123 The first paragraph.
The second paragraph.
The third paragraph.
The fourth paragraph.
注意: Internet Explorer 8 以及更早版本的浏览器不支持:nth-last-child()选择器.
输出结果:

jQuery仿京东图片变亮变暗效果,鼠标悬停图片之后该图片变亮,其他图片变暗。移开鼠标所有图片变亮。兼容主流浏览器,php中文网推荐下载! 使用方法: 1、head区域引用文件lrtk.css及js库,animate.js是另外编写的动画函数。
3、:nth-of-type(n)
:nth-of-type(n)选择器匹配同类型中的第n个同级兄弟元素。
n可以是一个数字,一个关键字,或者一个公式。
示例如下:
123 This is a heading
The first paragraph.
The second paragraph.
The third paragraph.
The fourth paragraph.
输出结果:

4、:nth-last-of-type(n)
:nth-last-of-type(n)选择器匹配同类型中的倒数第n个同级兄弟元素。
n 可以是一个数字,一个关键字,或者一个公式。
立即学习“前端免费学习笔记(深入)”;
示例如下:
123 This is a heading
The first paragraph.
The second paragraph.
The third paragraph.
The fourth paragraph.
注意: Internet Explorer 8以及更早版本的浏览器不支持:nth-last-of-type() 选择器.
输出结果:

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









