代码实例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> p:only-of-type { background:#ff0000; } </style> </head> <body> <div><p>This is a paragraph.</p></div> <div><p>This is a paragraph.</p><p>This is a paragraph.</p></div> </body> </html>
尝试一下 »
点击“尝试一下”按钮查看在线实例
定义和用法
:only-of-type选择器匹配属于同类型中唯一同级元素。