Forums

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

Home Forums CSS nth-child – slider – nested div

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #152337
    Nathan Gross
    Participant

    Perhaps this is really simple but for some reason I can’t wrap my head around it.

    I have a slider set up on a site. I’d like every even slide to have a different color background. There are some nested divs that make up each slide. The background color is set on the second level div.

    Here is a failed attempt using codepen:

    http://cdpn.io/sgrIx

    Is this even possible?

    #152345
    Paulie_D
    Moderator

    I think is the problem.

    .slider:nth-child(even) .level-1 .level-2 {
      background-color: red;
    }
    

    The slider isn’t a child so nothing is being selected.

    I think this (raw CSS) might be what you are after

    .slider .level-1:nth-child(even) .level-2 {
      background-color: red;
    }
    

    http://codepen.io/anon/pen/vgJwe

    #152363
    Nathan Gross
    Participant

    Perfect. That’s exactly it. Thanks Paulie_D!!

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