css(二)

来源:互联网 发布:f35知乎 编辑:程序博客网 时间:2024/05/01 11:13

15、p:first-child {font-weight: bold;}
li:first-child {text-transform:uppercase;}
第一个规则将作为某元素第一个子元素的所有 p 元素设置为粗体。第二个规则将作为某个元素(在 HTML 中,这肯定是 ol 或 ul 元素)第一个子元素的所有 li 元素变成大写。
提示:最常见的错误是认为 p:first-child 之类的选择器会选择 p 元素的第一个子元素。

(1)

<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>
 

16、:lang 伪类使你有能力为不同的语言定义特殊的规则。在下面的例子中,:lang 类为属性值为 no 的 q 元素定义引号的类型:
<html>
<head>

<style type="text/css">
q:lang(no)
   {
   quotes: "~" "~"
   }

</style>

</head>

<body>
<p>文字<q lang="no">段落中的引用的文字</q>文字</p>
</body></html>

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

原创粉丝点击