我试图选择第一个h1在一个div名为detail_container类。它的工作原理如果h1是这个div中的第一个元素,但如果它在这个ul之后,它将不工作。
<style type="text/css"> .detail_container h1:first-child { color:blue; } </style> </head> <body> <div class="detail_container"> <ul> <li></li> <li></li> </ul> <h1>First H1</h1> <h1>Second H1</h1> </div> </body> </html>