Forums

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

Home Forums CSS [Solved] Last-child

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

    Hello.
    I would like every .asset inside an li:last-child to be green.
    However, inside the 3rd li, i would like that 3.1 and 3.2 to be red.
    The same with 3.3.1, 3.3.2 and 3.3.3. Only 3.3.3 should be green.

    How can i accomplish this?

    I have this fiddle.
    http://jsfiddle.net/7p9ujapt/1/

    Thanks in advance.

    #210572
    TheDoc
    Member

    These types of selectors can be really tricky to get, but you did the right thing by opening up a JSFiddle (I prefer Codepen :D ). What you’re looking for is something like this:

    li:last-child > .asset {
      color: green;
    }
    

    That will make the immediate .asset child of li:last-child to be green, as seen here: http://codepen.io/graygilmore/pen/e816f974913df05472e0ccb445957ced

    #210574
    pauloreal
    Participant

    Thanks for the answer. It does what i need.
    Could you please explain me why this solution only affects the last-child since all .asset are direct children of the li:last-child?

    #234643
    TheDoc
    Member

    Sure! > makes it only check one level deep. That’s what I meant by saying “immediate” child.

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