一, 效果图。
二,代码。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS 分组和嵌套</title> <style> h1, h2, p { color: green; } .marked { background-color: red; } .marked p { color: white; } </style> </head> <body> <h1>hello </h1> <h2>span</h2> <p>this is a paragraph</p> <div class="marked"> <p>this is p</p> </div> </body> </html>
参考资料:《菜鸟教程》