2013-10-09 38 views
0

我需要把margin-right:0px每3個div。無限使用CSS nth孩子

其實我用這個代碼,但因爲WordPress的都瘋了,不和的index.php工作archive.php正確的:在第一第三格

.post {position:relative !important;float:left !important;width:207px !important;margin-right:24px;} 
.post:nth-child(4n+0) {margin-right:0px !important;} 

但是,只有做到這一點,但不是在6, 9,12 ....爲什麼?

<div class="post"></div> */ margin-right:24px; 
<div class="post"></div> */ margin-right:24px; 
<div class="post"></div> */ margin-right:0px; 
<div class="post"></div> */ margin-right:24px; 
<div class="post"></div> */ margin-right:24px; 
<div class="post"></div> */ margin-right:0px; 
<div class="post"></div> */ margin-right:24px; 
<div class="post"></div> */ margin-right:24px; 
<div class="post"></div> */ margin-right:0px; 

我有9個職位的頁面,有可能放於CSS指定的div:第一div.second ....有不同的CSS?

我不能用第n個孩子,因爲沒有在我的wordpress

回答

0

使用:nth-child(3n)正常工作的目標3/6/9號等。

和它的作品如預期..也許你沒有看到它由於佈局..

演示在http://jsfiddle.net/tY2Dh/


更新(更新問題後)

你的CSS規則的目標與分配category-pro類元素。

但是你的html元素有一個post類分配給他們。

您需要的category-pro類的規則添加到這些因素,或改爲

.post{..} 
.post:nth-child(3n){...} 

+0

不要在我的WordPress的工作,我不知道爲什麼。我有9個網頁,可以把CSS指定爲div:第一個div.second ....與不同的CSS? – vektor

+1

@vektor,你可以發佈一個鏈接嗎? –

+0

@vektor,也''nth-child()'不會在IE8上工作(*如果你看到問題在那裏.. *) –