Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3: How to select every 4th and 5th element

I'm new to these selectors and I was wondering how I would go about doing such a thing.

My selector needs to select the 4th and 5th elements, but then it needs to keep doing so. So it'd need to select 4, 5, 9, 10, 14, 15 and so on.

How is this possible? At the moment I can select every third item like so:

.pure-g-r .pure-u-1-3:nth-child(3n+3)

But I'm not sure how I can translate that into what I need.

Thanks for any help.

like image 929
Phill Avatar asked Sep 22 '13 10:09

Phill


2 Answers

You actually want to select every couple from the 4th and 5th element, with jumps of 5.

So, just use the following two comma-separated selectors.

.pure-g-r .pure-u-1-3:nth-child(5n + 4), .pure-g-r .pure-u-1-3:nth-child(5n)

jsFiddle Demo

Result

like image 96
Itay Avatar answered Nov 03 '22 00:11

Itay


a little nth-child tester page: http://css-tricks.com/examples/nth-child-tester/

.pure-u-1-3:nth-child(5n + 4), .pure-u-1-3:nth-child(5n){
    color:red;
}

http://css-tricks.com/useful-nth-child-recipies/

http://css-tricks.com/how-nth-child-works/

like image 26
Gildas.Tambo Avatar answered Nov 02 '22 22:11

Gildas.Tambo