nth-child与nth-of-type区别
示例详细理解:nth-child(n)与:nth-of-type(n)区别

childselector:nth-child(index)
1,子选择器(childselector,这里是p选择器)选中元素的父级元素ul,
得到所有子元素(包括自己和所有兄弟元素)(l1,p1,p2,l2,p3),
从1开始计数排好序。从所有子元素中开始选
2,①第index个元素②还要必须符合childselector。
结论:这两个条件都要符合, 有一个不符合就选不中。
例如:p:nth-child(2) 1,第2个,2,必须是p元素
例如:p:nth-child(1) 1,第1个不是p元素 就选不中
childselector:nth-of-type(index)
1,子选择器(childselector,这里是p选择器)选中元素的父级元素ul,
得到符合子选择器(childselector)子元素(包括自己和符合子选择器(childselector)兄弟元素)
(p1,p2,p3),从1开始计数排好序。从所有子元素中开始选
2,①第index个元素②还要必须符合childselector。结论:这两个条件都要符合, 有一个不符合就选不中。
p:nth-child(1) 第1个 必须是p元素 选中p1
p:nth-child(2) 第2个 必须是p元素 选中p2
简短理解
childselector:nth-child(index)
1,childselector元素的父元素的所有子元素,开始index从1开始计数
2,childselector,index:两个约束的地方
childselector:nth-of-type(index)
1,childselector元素的父元素的childselector子元素,开始index从1开始计数
2,childselector,index:两个约束的地方
nth的中文意思
形容词(一系列事物中)第 n 次的,第 n 位的
The story was raised with me for the nth time two days before the article appeared
在我第n次被问及这件事情的两天后,相关文章登了出来。 ----柯林斯高阶英汉双解学习
扩展
:first-child :last-child :only-child :nth-child(n) :nth-last-child(n)
:first-type :last-type :only-type :nth-of-type(n) :nth-last-type(n)
例子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
/*
这个选择不中
原因参考http://www.cnblogs.com/leee/p/7275860.html
li:nth-child(2) {
color: green;
} */
p:nth-child(2) {
color: green;
}
li:nth-of-type(2) {
color: red;
}
</style>
</head>
<body>
<ul>
<li>li1</li>
<p>p1</p>
<li>li2</li>
<p>p2</p>
<li>li3</li>
</ul>
</body>
</html>
运行
nth-child与nth-of-type区别的更多相关文章
- linux中查找命令find、locate、whereis、which、type区别
linux中查找命令find.locate.whereis.which.type区别 1. find Java代码 find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件.与查询数据库(/ ...
- instance与type区别
class Foo(object): pass class Bar(Foo): pass obj = Bar() # isinstance用于判断,对象是否是指定类的实例 (错误的) # isinst ...
- [Swift]LeetCode400. 第N个数字 | Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is ...
- python 内建函数isinstance的用法以及与type的区别
isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数object是classinfo的实例,或者object是class ...
- Sass函数:列表函数nth
语法: nth($list,$n) nth() 函数用来指定列表中某个位置的值.不过在 Sass 中,nth() 函数和其他语言不同,1 是指列表中的第一个标签值,2 是指列给中的第二个标签值,依此类 ...
- Doctype作用,标准模式与兼容模式的区别
<!DOCTYPE>声明位于位于HTML文档中的第一行,处于 <html> 标签之前.告知浏览器的解析器用什么文档标准解析这个文档.DOCTYPE不存在或格式不正确会导致文档以 ...
- orcle自定义类型type/create or replace type
一.type / create or repalce type 区别联系 相同: 可用关键字create type 或者直接用type定义自定义类型, 区别: create type 变量 as ta ...
- Python type() 函数
描述 type() 函数如果你只有第一个参数则返回对象的类型,三个参数返回新的类型对象.类似isinstance() isinstance() 与 type() 区别: type() 不会认为子类是一 ...
- 转载:oracle 自定义类型 type / create type
标签:type create oracle object record 一:Oracle中的类型有很多种,主要可以分为以下几类: 1.字符串类型.如:char.nchar.varchar2.nvarc ...
- setContentView和inflate区别
一般用LayoutInflater做一件事:inflate inflate这个方法总共有四种形式(见下面),目的都是把xml表述的layout转化为View对象.其中有一个比较常用,View infl ...
随机推荐
- CGo中传递多维数组给C函数
转自:http://www.cnblogs.com/cobbliu/p/5035358.html package main /* #include <stdio.h> #include & ...
- MySQL 之 MyTop实时监控MySQL
CentOS下使用MyTop实时监控MySQL MyTop的项目页面为:http://jeremy.zawodny.com/mysql/mytop/ MyTop安装 安装依赖包 yum instal ...
- 关于HSTS
HSTS(HTTP Strict Transport Security) 当用户在浏览器中输入一个域名,如果没有注明前缀(也就是没输入"http"的时候)的时候,浏览器会默认按照h ...
- system 系统调用、gcc编译过程
system 库函数的功能是执行操作系统的命令或者运行指定的程序 #include <stdio.h> #include <stdlib.h>//引入库 int main() ...
- vue-cli 项目搭建
vue-cli 项目搭建 1.首先需要安装nodejs(安装省略). 2.用node安装vue-cli. npm install -g vue-cli 3.新建目录用来存放工程. 新建一个vue项 ...
- 如何通过权限控制EXP导出指定的表
今天一客户朋友咨询一个Oracle数据库用户EXP权限控制的问题,问我有没有办法可以解决.问题是这样的: 目前他们那边有外面的开发公司人员在核心系统做开发,考虑到系统数据的敏感性,给他们建了一个数据库 ...
- Python并发编程一(多进程)
1.背景知识(进程.多道技术) 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一 ...
- 【Jmeter自学】Jmeter实战-web程序(六)
1.确认测试被测对象 **网站 windows环境 2.需求: 并发登录性能测试 3.场景设置: 1s增加2个线程,运行2000次 分别查看20,,60并发下的表现 4.监控 成功率 响应时间 标准差 ...
- tree-data
[{ label: '一级 1', children: [{ label: '二级 1-1', children: [{ label: '三级 1-1-1' }] }] }, { label: '一级 ...
- scp(secure copy)安全拷贝
scp(secure copy)安全拷贝 (1)scp定义: scp可以实现服务器与服务器之间的数据拷贝.(from server1 to server2) (2)基本语法 命令 递归 要拷贝的文 ...