欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!

 

您兴许运用 :first-child 伪类来决意元素的第一个子元素。这个特定伪类很简单受到误会,以是有需要举例来阐明。思虑如下符号:

<div>
<p>These are the necessary steps:</p>
<ul>
<li>Intert Key</li>
<li>Turn key <strong>clockwise</strong></li>
<li>Push accelerator</li>
</ul>
<p>Do <em>not</em> push the brake at the same time as the accelerator.</p>
</div>

在上面的例子中,作为第一个元素的元素包孕第一个 p、第一个 li 和 strong 和 em 元素。

给定如下划定规矩:

p:first-child {font-weight: bold;}
li:first-child {text-transform:uppercase;}

第一个规则将作为某元素第一个子元素的悉数 p 元素配置为粗体。第二个规定将作为某个元素(在 HTML 中,这必然是 ol 或 ul 元素)第一个子元素的所有 li 元素变成大写。

请接见该链接,来搜检这个 :first-child 实例的效果。

示意:最常见的舛错是以为 p:first-child 之类的决议器会选择 p 元素的第一个子元素。

剖明:必须声明 <!DOCTYPE>,这样 :first-child 才略在 IE 中见效。

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/rumen/r52607.shtml