Forums

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

Home Forums CSS Are div and div:nth-child(1) equivalent?

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #283192
    johnywhy
    Participant

    Are
    div
    and
    div:nth-child(1)
    equivalent?

    thx

    #283194
    Beverleyh
    Participant

    No, they are not equivalent.

    div = all div elements

    div:nth-child(1) = the first div in a group of sibling div elements

    #283198
    Paulie_D
    Member

    With respect to Beverlyh this

    div:nth-child(1) = the first div in a group of sibling div elements

    Is not quite correct.

    div:nth-child(1) = the first div which is also the first child of a parent.

    https://codepen.io/Paulie-D/pen/exXzpg

    For Beverleys exmaple to be true would need to be

    div:nth-of-type(1) = the first div in a group of sibling div elements

    #283214
    Beverleyh
    Participant

    Thanks Paulie_D. I should have been more explicit with my wording. The markup I was visualising when I wrote it was an exclusive group of divs where the first child would also be a div.

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