专注前端素材!
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>素材8网教程(study.sucai8.cn)</title> <style> p:first-child { background-color:yellow; } </style> </head> <body> <p>This paragraph is the first child of its parent (body).</p> <h1>Welcome to My Homepage</h1> <p>This paragraph is not the first child of its parent.</p> <div> <p>This paragraph is the first child of its parent (div).</p> <p>This paragraph is not the first child of its parent.</p> </div> <p><b>注意:</b> :first-child作用于 IE8以及更早版本的浏览器, DOCTYPE必须已经声明.</p> </body> </html>
运行结果