开发者

How to add a style using jQuery to the 3rd, 6th, etc. (n * 3) elements within a div?

I'm designing a website w开发者_如何转开发ith divs with the following fashion:

<div id="showcase">
 <div class="project"> <!-- this is the first row -->
 <div class="project"> <!-- this is the first row -->
 <div class="project"> <!-- this is the first row -->
 <div class="project"> <!-- this is the second row -->
 <div class="project"> <!-- this is the second row -->
 <div class="project"> <!-- this is the second row -->
 <div class="project"> <!-- this is the third row -->
 <div class="project"> <!-- this is the third row -->
 <div class="project"> <!-- this is the third row -->
 </div> 
</div>

I want to remove right margin to the "last" div of a row (each row has 3 divs).

Any suggestions to accomplish this?


I think you want the nth-child selector:

$('#showcase .project:nth-child(3n)').addClass('margin-adjuster');

Here's a quick demo that just does a color change to show you how it works:

http://jsfiddle.net/ambiguous/YDvGw/

You could do a .css({ marginRight: 0 }) if you just wanted to change the margin without messing around with another class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜