Forums

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

Home Forums CSS Is div + div + div + div equivalent to div :nth-of-type(3) ?

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

    hi

    Is
    div + div + div + div
    equivalent to
    div :nth-of-type(3)
    ?

    #283197
    Beverleyh
    Participant

    No.

    The + adjacent sibling selector only matches elements when they immediately follow. So the first example would only match the 4th div (plus the 5th, 6th, 7th, 8th, etc.) in a chain of sibling divs, where no other sibling elements break them apart.
    “From the 4th div, and all adjacent siblings divs thereafter, until something breaks them apart.”

    div:nth-of-type(3) would match the 3rd sibling div regardless of whether other sibling elements were inbetween to break the chain.
    “Select the 3rd sibling div, ignoring all other sibling elements.”

    div :nth-of-type(3) would match any 3rd sibling element inside a div regardless of other sibling elements.
    “Select 3rd sibling elements inside a div, ignoring all other sibling elements.”

    You can always try these examples out yourself to see them working, you know.

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