2017-02-18 30 views
0

我想在600 * 600格内放置3 200 * 200的矩形div。分辨率为25像素。我的第一个代码工作正常。但是当我尝试应用第n个孩子(1)和第n孩子(2)它不工作。nth-child(数字)选择器的css没有得到应用

https://jsfiddle.net/user1989/L20fn90L/

,如果我改变风格一部分

#two-parent :nth-child(0){ 
margin-top:25px; 
width:200px; 
height:200px; 
background-color : black; 

float:left; 

} 
#two-parent :nth-child(1){ 
margin-top:25px; 
position:relative; 
width:200px; 
height:200px; 
background-color : orange; 
margin-left:25px; 
float:left; 
} 

孩子选择是没有得到应用。

回答

3

您使用DIV作为子容器,则CSS声明应该做的工作:

#two-parent div:nth-child(1) { /** :nth-child(1) for 1st child **/ 
    /** Declaration **/ 
} 
#two-parent div:nth-child(2) { /** :nth-child(2) for 2nd child **/ 
    /** Declaration **/ 
} 
+0

谢谢den Isahac – smraj