wharfdale
wharfdale

Reputation: 752

Effect every 3rd element/div

I've tried adding an element in my CSS to remove the margin-right of every third div. Just seems to be effecting the 3rd and 7th for some reason though. Need it to work on 3rd, 6th, 9th etc...

CSS

.shopping-product { background-color: #fff; position: relative; border: 1px solid #eee; width: 200px; height: 250px; margin-right: 20px; float: left; padding-bottom: 20px; }
.shopping-product:nth-child(4n) { margin-right: 0; }

Is (4n) correct for every 3rd div?

Upvotes: 0

Views: 158

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115232

Use 3n instead which will select 3rd,6th,9th,....

.shopping-product:nth-child(3n) { margin-right: 0; }

Upvotes: 2

Related Questions