css selectors - How to select only some children in CSS? -


i have divs in html, dynamic number of divs

how select divs 2,5,8,11 ?

i tried :nth-child(2n+3) not need

here's code:

<!doctype html> <html>   <head>       <style>           .a:nth-child(2n+3) { background:#ff0000; }       </style>   </head>   <body>     <p class="a">the first paragraph.</p>     <p class="a">the second paragraph.</p>     <p class="a">the third paragraph.</p>     <p class="a">the fourth paragraph.</p>     <p class="a">the fifth paragraph.</p>     <p class="a">the sixth paragraph.</p>     <p class="a">the seventh paragraph.</p>     <p class="a">the 8 paragraph.</p>     <p class="a">the ninth paragraph.</p>     <p class="a">the seventh paragraph.</p>     <p class="a">the 8 paragraph.</p>     <p class="a">the ninth paragraph.</p>   </body> </html> 

edit if 2,5,8,11 needed answer be:

p:nth-child(3n+2) {    background: #ccc; } 


select paragraphs 2, 3, 5, 8, 11:

p:nth-child(3n+2),p:nth-child(3) {    background: #ccc; } 

fiddle

i had add p:nth-child(3) separately because doesn't fit in general pattern of +3 each time.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -