我正在使用以下方式设计一个包含div的网站:
<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>
我想删除右边距到行的“最后”div(每行有3个div)。
有任何建议可以实现这一目标吗?
答案 0 :(得分:2)
我想你想要nth-child
selector:
$('#showcase .project:nth-child(3n)').addClass('margin-adjuster');
这是一个快速演示,只是做一个颜色变化,向您展示它是如何工作的:
如果你只是想改变边距而不是乱搞另一个课,你可以做.css({ marginRight: 0 })
。