Style every
element that is the only child of its parent with CSS
使用CSS:only-child选择器为每个
设置样式
是其父项的唯一子项的元素。
您可以尝试运行以下代码来实现:only-child选择器
现场演示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <!DOCTYPE html> <html> <head> <style> p:only-child { background: orange; } </style> </head> <body> Heading <p><center>[wp_ad_camp_2]</center></p><p> This is a paragraph. </p> <p> This is a paragraph. </p> <p> This is a paragraph. </p> <p> This is a paragraph. </p> </body> </html> |