:only-child选择器匹配属于父元素中唯一子元素的元素。
p:only-child { background:#ff0000; }
HTML
<div><p>This is a paragraph.</p></div> <div><span>This is a span.</span><p>This is a paragraph.</p></div> <p><b>注意:</b> Internet Explorer 8以及更早版本的浏览器不支持 :only-child选择器.</p>
CSS
p:only-child { background:#ff0000; }
执行结果
This is a paragraph.
This is a paragraph.
注意: Internet Explorer 8以及更早版本的浏览器不支持 :only-child选择器.