Forums

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

Home Forums CSS nth-last-child(???)

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #41155
    alexmccabe
    Participant

    I have a peculiar want. The last three children in an li. I wish to target them only. Is it possible to do so?

    I guess I could do them individually like so:

    li:last-child,
    li:nth-last-child(2),
    li:nth-last-child(3) {
    margin-bottom: 0;
    }

    but I would rather not, is there a way around this?

    #116286
    Paulie_D
    Member

    Nope…the code you gave is the way to go unless you add a specific class or use JS

    #116294
    Senff
    Participant

    I was about to go the same route: giving all elements a certain style (the one you want for the last X element) and then use another style on top of that, EXCLUDING the last three.

    #116295
    Paulie_D
    Member

    Damn…that works…tried it a different way and couldn’t get it.

    #116363
    Paulie_D
    Member

    @joshuanhibbert THAT’s what I was trying to figure out. I KNEW there was a ‘minus’ in there somewhere.

    Bingo!

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