I am breaking my head to achieve something quite relatively simple here.
I need to select every 3rd and 4th element on my page, how could I do that using css :nth-child()?
JS answers also welcome.
Thanks a lot.
***EDIT
Apologies guys my question was badly written. I attached an example below of what I need.
This is the outcome I need, http://jsfiddle.net/8FXL6/
<li></li>
<li class="highlight"></li>
<li class="highlight"></li>
<li></li>
<li></li>
etc
Without hardcoding the class names.
How about using css only?
Every third element:
*:nth-child(3n+3) {color: red}
Every fourth element:
*:nth-child(4n+4) {color: blue}
Here's demo on jsfiddle: http://jsfiddle.net/dufsx/
This can be solved using CSS only
*:nth-child(4n+2){background:blue;color: white;}
*:nth-child(4n+3){background:blue;color: white;}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.