为了账号安全,请及时绑定邮箱和手机立即绑定

:nth-child(n)的使用问题!

:nth-child(n)的使用问题!

div,p:nth-child(2){ color: red; }div:nth-child(2){ color: red; } p:nth-child(2){ color: red; } <div id="head"> <h1>标题A</h1> <p>段落A</p> <p>段落B</p> </div> <div id="body"> <h2>标题B</h2> <p>段落A</p> <p>段落B</p> </div>两个元素选择器,最后实现的效果不相同,能解释一下吗?
查看完整描述

4 回答

已采纳
?
学习js

TA贡献85条经验 获得超55个赞

逗号表示并列关系,div,p:nth-child(2){ color: red; }等价于div{color:red;}和p:nth-child(2){ color: red; }

查看完整回答
3 反对 回复 2017-02-15
?
echo_kinchao

TA贡献600条经验 获得超86个赞

肯定不相同啊  第一个 是   div 和 第二个p红色   第二个是  第二个div 和 第二个p都红色 

查看完整回答
1 反对 回复 2017-02-15
?
woshiajuana

TA贡献211条经验 获得超152个赞

div,p:nth-child(2){ color: red; }这段

分开来写就是div{color:red}    p:nth-child(2){ color: red; }

,英文下的逗号分隔后,就是两个选择器了

div:nth-child(2){ color: red; },p:nth-child(2){ color: red; } 才等同于

div:nth-child(2){ color: red; }

p:nth-child(2){ color: red; }


查看完整回答
1 反对 回复 2017-02-15
?
YANhan

TA贡献1条经验 获得超0个赞

div:nth-child(2),p:nth-child(2){ color: red; }想简写的话也应该是这个样子的吧。

查看完整回答
反对 回复 2017-02-16
  • 4 回答
  • 0 关注
  • 2095 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信