Forums

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

Home Forums CSS :hover state affect a non-child item

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #41301
    Blackhawkso
    Member

    Hey guys.

    Is there a way that I can get a :hover state to affect an item that isn’t a direct child of itself.

    So say for example you had this code.

    Hover on me

    Is there a way using css that I can use a.link:hover to trigger something on the span.box even thought the span.box isn’t inside the a.link.

    Cheers everyone

    #117025
    Blackhawkso
    Member

    I know that it should be a div and not a span but when i put div in this post it won’t display properly and only shows the a link

    #117026
    TheDoc
    Member

    In your specific example you could use a sibling selector:

    .link:hover + .box {
    /* your styles */
    }

    #117027
    Blackhawkso
    Member

    @TheDoc Nice cheers. i’m guessing this won’t work if the affected item is outside of a wrapper element?

    or to explain myself better they both need to be a child of the same parent element

    #116976
    TheDoc
    Member

    Sorry I missed your messaged. Josh hit the nail on the head. That’s why I said “in your specific example” because I wasn’t sure if you were making a basic example of something more complicated that you were trying to do.

    #117239
    Blackhawkso
    Member

    Right ok got it cheers everyone

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