码迷,mamicode.com
首页 > 其他好文 > 详细

:first-of-type{}伪类选择器

时间:2015-03-04 21:01:32      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

如果你只想选择某一个指定标签下的一个元素,那么first-of-type可以实现(注意:a:first-child是选择所有父级节点下面所有第一个a元素)

 1 <div class="sidebar">
 2 
 3   <p>你好1</P>
 4 
 5   <p>你好2</P>
 6 
 7 </div>
 8 
 9 <div class="main">
10 
11   <p>你好3</P>
12 
13   <p>你好4</P>
14 
15 </div>

如上代码,如果你的css中是这样写 

1 .sidebar p:first-of-type{  background:red;  }

则只会选择sidebar中第一个p,如果你这样写

p:first-child{background:red}

那么会选择sidebar和main中的第一个p元素

当然,还有last-of-type{}

:first-of-type{}伪类选择器

标签:

原文地址:http://www.cnblogs.com/hongrunhui/p/4314174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!