简体   繁体   English

使用nth-child选择特定的div类

[英]Select specific div class using nth-child

Please have a look at http://jsfiddle.net/kV7Uq/1/ 请看一下http://jsfiddle.net/kV7Uq/1/

.productList div.grid:nth-child(4n+5){
clear:left;
}

What I'm trying to achieve is to create a 4 column grid. 我想要实现的是创建一个4列网格。 The above code used in the fiddle seems to be just fine - but if you look at that fiddle there is no 4 column grid. 小提琴中使用的上述代码似乎很好-但是,如果您查看该小提琴,则没有4列网格。

<div class="pageNav"></div>
<div class="pageHeading"></div>

The above two divs that are also child divs of the container div, and located prior to the grid divs are causing a conflict. 上面的两个div也是容器div的子div,并且位于网格div之前,这引起了冲突。 If those two divs are removed, the grid comes out just fine. 如果将这两个div删除,网格就很好了。 I'm not sure if this is even fixable, please help - thank you. 我不确定这是否可以解决,请帮忙-谢谢。

Just offset it by 2 to compensate for those divs. 只需将其偏移2即可补偿这些div。 Instead of +5 , use +3 . 代替+5 ,使用+3

.productList div.grid:nth-child(4n+3){
    clear:left;
}

http://jsfiddle.net/kV7Uq/2/ http://jsfiddle.net/kV7Uq/2/

If you don't want the very first box to have the clear: left then it would be +7 . 如果您不希望第一个框具有clear: left那么它将为+7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM