The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Issue with :nth-child()

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #44014


    I am using the **:nth-child()** pseudo selector to target a specific element. There seems to be an issue with the result and I can’t quite figure out how to solve it.

    Below is a simple test case…Essentially the child selector is one element off the intentional target. All elements share the same class name, except for the first…And this seems to be where the nth count is thrown off.

    The goal is to exclude the first element with the different class name…in this case that would be **.top** while targeting one element from the series of **.box** classes.


    Is there anyway to go about this properly? Any Help is appreciated.

    Thank you


    Unfortunately, you can’t use nth-child to select classes only elements.

    Previously discussed:


    If there are going to be elements in there that you don’t want to to be counted, you should be using `nth-of-type`.


    As I said, you can’t apply it to classes…only elements.

    `nth-child` **is** a class (albeit pseudo) and you can’t apply a class to a class.

    EDIT: nth-of-type won’t work either AFAIK…same reason.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘CSS’ is closed to new topics and replies.