CSS 参考手册
CSS3 :only-of-type 选择器
匹配属于同类型中唯一同级元素的p元素的背景颜色
源代码:
点击运行 »
<!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>
运行结果:
点击运行 »