首页 > Web开发 > 详细

css笔记03:伪类first-child

时间:2015-06-29 22:05:38      阅读:226      评论:0      收藏:0      [点我收藏+]

1. 匹配第一个 <p> 元素

在下面的例子中,选择器匹配作为任何元素的第一个子元素的 p 元素:

<html>
<head>
<style type="text/css">
p:first-child {
  color: red;
  } 
</style>
</head>

<body>
<p>some text</p>
<p>some text</p>
</body>
</html>

2.匹配所有 <p> 元素中的第一个 <i> 元素

<html>
<head>
<style type="text/css">
p > i:first-child {
  font-weight:bold;
  } 
</style>
</head>

<body>
<p>some <i>text</i>. some <i>text</i>.</p>
<p>some <i>text</i>. some <i>text</i>.</p>
</body>
</html>

 

3.匹配所有作为第一个子元素的 <p> 元素中的所有 <i> 元素

<html>
<head>
<style type="text/css">
p:first-child i {
  color:blue;
  } 
</style>
</head>

<body>
<p>some <i>text</i>. some <i>text</i>.</p>
<p>some <i>text</i>. some <i>text</i>.</p>
</body>
</html>

 

css笔记03:伪类first-child

原文:http://www.cnblogs.com/hebao0514/p/4608460.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!