:only-of-type

:only-of-type选择器匹配属于同类型中唯一同级元素。

语法

p:only-of-type
{
background:#ff0000;
}

例子

HTML

<div><p>This is a paragraph.</p></div>

<div><p>This is a paragraph.</p><p>This is a paragraph.</p></div>

CSS

p:only-of-type
{
	background:#ff0000;
}

执行结果

This is a paragraph.

This is a paragraph.

This is a paragraph.

参考

相关页面

外部链接