第2章 选择器 =>选择子元素 P54
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择子元素</title>
<style type="text/css">
h1 > strong {
color:red;
}
</style>
</head>
<body>
<p>在某些情况下,可能并不相选择一个任意的后代元素,而是希望缩小范围,只选择另一个元素的子元素。例如,可能想选择只作为一个h1元素的子元素(而不是后代元素)的strong元素。为此可以使用子结合符,即大于号(>)</p>
<p>h1 > strong {color:red;}</p>
<h1>This is <strong>very</strong> important.</h1>
<h1>This is <strong>very</strong> important</h1>
<h1>This is <em>really <strong>very</strong> important</em></h1>
<p>选择器h1 > strong 可以解释为“选择作为h1元素的子元素的所有strong元素”。子结合符两边可以有空白符,这是可选的,因此h1 > strong 、h1> strong和h1>strong都是一样的。</p>
</body>
</html>
显示效果:

详细说明:

例如,a元素是strong元素的父元素,但是它又是p元素的子元素。可以用p > a和a > strong选择器来匹配这个片段中的元素,但是p > strong不行,因为strong是p的后代而不是其子元素。
还可以在同一个选择器中结合使用后代选择器和子选择器。因此,table.summay td > p 会选择作为一个td元素子元素的所有p元素,这个td元素本身从table元素继承,该table元素有一个包含summary的class属性