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= ...
 
随机推荐
- 数据库的四种语言(DDL、DML、DCL、TCL)
			
1.DDL (Data Definition Language )数据库定义语言 statements are used to define the database structure or sch ...
 - [Spring入门学习笔记][Spring的AOP原理]
			
AOP是什么? 面向切面编程 软件工程有一个基本原则叫做“关注点分离”(Concern Separation),通俗的理解就是不同的问题交给不同的部分去解决,每部分专注于解决自己的问题.这年头互联网也 ...
 - 解决ERROR 2006 (HY000): MySQL server has gone away
			
刚把博客从百度云搬到腾讯云,发现文章少了几篇.当时在导入dump数据的时候,就曾经发现mysql提示: ERROR 2006 (HY000): MySQL server has gone away N ...
 - struts2必需jar包
			
asm-3.3.jar commons-logging-1.1.3.jarasm-commons-3.3.jar freemarker-2.3. ...
 - JavaScript ----------------- 原型式继承
			
思想:借助原型可以基于已有的对象创建新对象,同时还不必因此创建自定义类型.为了达到这个目的,看看下面的实现方式 function object(o){ function F(){ } F.protot ...
 - tomcat6.0目录和server.xml详解
			
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,目前最新版本是6.x,相对5.x性能提升很多,主要优化了内存使用,增强IO能力,重新构造集群功能. 近期对Tomcat6.x作深入学习, ...
 - C#验证类 可验证:邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,IP (转)
			
namespace YongFa365.Validator { using System; using System.Text.RegularExpressions; /**//// <summ ...
 - SharePoint solution and feature management with PowerShell
			
/* Author: Jiangong SUN */ Hello, I want to introduce SharePoint solution and feature management usi ...
 - windows 下查看端口占用命令
			
cmd netstat -ano
 - MySQL 常用字段类型,介绍及其建表使用方法经验分享
			
由于工作的公司没有专业的DBA又经常需要建立各种各种的表来满足自己的业务逻辑,所以经常查看MySQL 手册或者谷歌查看相关资料,所以本人就根据我的工作经验和相关资料来介绍一下MySQL各种字段类型及其 ...