nth-child和nth-of-type的区别
以前一般都用:nth-child,后来知道了:nth-of-type,然后就一般用nth-of-type
它们两有什么区别呢?
首先来看个现象:
假如有这样一个HTML结构
<div class="post">
<p>我是段落1</p>
<p>我是段落2</p>
</div>
分别加上两个样式的效果
.post > p:nth-child(2){
background-color: red;
}

.post > p:nth-of-type(2){
background-color: yellow;
}

这个时候我们发现它们的效果是一样的,那么它们的区别是什么呢?别着急,看下面这个例子
这是HTML结构:
<div class="box">
<h1>我是标题</h1>
<p>我是段落1</p>
<p>我是段落2</p>
</div>
和案例1一样的样式加上去
.box > p:nth-child(2){
background-color: red;
}

.box > p:nth-of-type(2){
background-color: yellow;
}

如果我们把样式稍微改一下
.box > p:nth-child(1){
background-color: blue;
}

.box > p:nth-of-type(1){
background-color: blue;
}

这个时候:nth-child的效果就比较出乎意料了;
通过几个案例在来说两者的区别可能好理解一点:
"p:nth-chil(n)":p的父元素的第n个子元素,如果这个元素时p类型,那么就给它加上后面的样式,如果不是那就算了
"p:nth-of-type(n)":p的父元素的p类型的子元素的第n个
nth-child和nth-of-type的区别的更多相关文章
- ASP.NET控件<ASP:Button /> html控件<input type="button">区别联系
ASP.NET控件<ASP:Button />-------html控件<input type="button">杨中科是这么说的:asp和input是一样 ...
- Html中,id、name、class、type的区别
<input type="text" name="name" id="name" class="txt"> ...
- isinstance与type的区别
1.isinstance()内置函数 python中的isinstance()函数是python的内置函数,用来判断一个函数是否是一个已知类型.类似type. 2.用法: isinstance(obj ...
- python isinstance()与type()的区别
例如在继承上的区别: isinstance() 会认为子类是一种父类类型,考虑继承关系. type() 不会认为子类是一种父类类型,不考虑继承关系. class A: pass class B(A): ...
- class kind type sort区别
class多用于 级别比如高级货就是 first class,primary class等等,以此类推kind 和sort 基本一样,就像你说的,译为 种类,what kind of疑问,回答时用so ...
- python 内建函数isinstance的用法以及与type的区别
isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数object是classinfo的实例,或者object是class ...
- isinstance 和 type 的区别
class A: pass class B(A): pass isinstance(A(), A) # returns True type(A()) == A # returns True isins ...
- 【学习总结】Python-3- 类型判断之 isinstance 和 type 的区别
菜鸟教程-Python3-基本数据类型 关于类型查询: type() 函数:可以用来查询变量所指的对象类型 用 isinstance()函数:判断是否是某个类型 两者的区别: type()不会认为子类 ...
- const type& 与 type& 的区别
const type& 与 type& 是C/C++编程中容易混淆的两个知识点,现在以 cont int& 与 int& 为例讲解: 1.int& 讲解 int ...
- form表单重复提交,type=“button”和type=“submit”区别
公司测试提了一个项目后台在IE浏览器下(360,firefox就没问题)出现数据重复的问题,调试了好久终于发现问题所在,也不知道是谁写的代码,醉醉的.... 错误地点: <input type= ...
随机推荐
- Oracle:grouping和rollup
Oracle grouping和rollup简单测试 SQL,,,) group by department_id order by department_id; DEPARTMENT_ID SUM( ...
- Docker搭建私有仓库
1,下载仓库镜像. docker pull registry //主要用于搭建私有仓库的. 2,将宿主机端口映射到容器中去,容器的5000端口是不能更改的. docker run -d -p ...
- EffectiveC#1--尽可能的使用属性(property),而不是数据成员(field)
1.属性可以进行数据绑定 2.可以做数据安全校验.在对数据检测时,如果发现数据不满足条件,最好以抛出异常的形式来解决 如下代码不可取 public string Name { get { if(thi ...
- 推荐几个常用的jquery ui 框架
jQuery ui框架很多,除了官方提供的jquery UI(如果你还不知道什么是jQuery UI,请看下载了jquery ui后如何使用),还有很多第三方提供的ui框架,因官方提供的jquery ...
- MongoDB学习笔记06
在shell中删除一个集合,执行db.test.drop()或者db.runCommand({"drop":"test"}),在MongoDB中命令其实是作为一 ...
- Code Complete阅读笔记(三)
2015-05-26 628 Code-Tuning Techniques ——Even though a particular technique generally represen ...
- iOS指纹识别
#import "ViewController.h" #import <LocalAuthentication/LocalAuthentication.h> @inte ...
- Mybatis Generator最完整配置详解
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...
- UVA 10253 Series-Parallel Networks (树形dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Series-Parallel Networks Input: standard ...
- (原)ubuntu14及ubuntu16中安装docker
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5653739.html 参考网址: http://blog.csdn.net/yangzhenping/ ...