Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS : selecting multiple nth-child

Say I have this css :

div div p:nth-child(1),
div div p:nth-child(2),
div div p:nth-child(3),
div div p:nth-child(4),
div div p:nth-child(5) {
}

This will select nth-child elements from 1 until 5.

And here are shortcuts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

div div p:nth-child(n+1):nth-child(-n+5){
}

OR

div div p:nth-child(-n+5){
}

My question is,

How to select not the first element from 1 to 5, but the second element from 2 to 5 ?

So basically if I have this HTML :

<div>
    <div>
        <p></p>
        <p></p>
        <p></p>
    </div>
    <div>
        <p></p>
        <p></p>
        <p></p>
    </div>
    <div>
        <p></p>
        <p></p>
        <p></p>
    </div>
    <div>
        <p></p>
        <p></p>
        <p></p>
    </div>
    <div>
        <p></p>
        <p></p>
        <p></p>
    </div>
</div>

I would like it to apply a css background-color: red, only from the second div > p, and this until the 5th one.

>Solution :

perhaps something like this would work?

div div p:not(:first-child)

found in Style every thing except first child

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading