2013-12-19 88 views
1
.class + p:first-child{ 

} 

上面的代碼不起作用,除非它是元素而不是類,比如p:first-child。選擇類名稱的第一個元素css基礎

<div class="wrap"> 
<h3></h3> 
<div style="clear:both"></div> 
<p></p> 
<p></p> 
<p></p> 
<p></p> 

如何根據類包裝選擇第一個p?我不想在p上申請班級名稱。

回答

1

不能使用:first-child這裏,因爲在這種情況下class:wrapfirst-child<h3>。在您需要的情況下,嘗試這種

.wrap > p:nth-of-type(1) { 
    color:red 

} 

小提琴是HERE

相關問題