CSS Selector N-th child but only even numbers ?

4 replies
  • WEB DESIGN
  • |
Hello. I would like to ask you guys how to select only those child elements that are integer and even numbers of their parent ?

Example:

Parent > Child 1 > Child 2 > Child 3 > Child 4

I want to select all even childs of a particular parent which in this case will be '2' and '4'. I want to select it only once and not go each time with n-th child method.

Cheers
#child #css #nth #numbers #selector
  • Profile picture of the author yestyle
    Banned
    Can you show real code ? and what do you want to do ?
    I am interested in CSS and we can discuss on this interesting topic
    {{ DiscussionBoard.errors[8413929].message }}
  • Profile picture of the author Craig Allen
    Well the code isn't yet made as I was just planning theoretical steps and trying to figure out the correct approach for most of the things .

    I've figured out how to select only even child elements. For all those who would want to know :

    element:nth-child(even) {}

    As simple as that

    Basically if we would want to select each even li in ul parent container then we would have to write like so :

    <ul class="pricing">
    <li>First</li>
    <li>Second</li>
    <li>Third</li>
    <li>Fourth</li>
    </ul>
    and CSS for it :

    ul.pricing:nth-child(even) {
    color:pink;
    }

    which would give each even child of ul container a color of pink . Correct me if I'm wrong.

    Cheers
    Signature
    You Can't Miss This!

    Business card included, Unlimited Revisions, rich portfolio.
    Please help us grow simply by clicking the link above
    {{ DiscussionBoard.errors[8413946].message }}
  • Profile picture of the author yestyle
    Banned
    Hello,

    That's is working code, I tested

    <style type="text/css">
    ul.pricing :nth-child(2n+2) {
    color:#FF0080;
    }
    </style>
    you need to edit a bit on your code

    Cheers!
    {{ DiscussionBoard.errors[8414180].message }}
  • Profile picture of the author Andrew H
    This is a ridiculous post. You can find the proper (ie: not the above) answer to this by spending 5 seconds on google.
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8414359].message }}

Trending Topics