Using only CSS, show div on hover over

后端 未结 13 1109
时光取名叫无心
时光取名叫无心 2020-11-22 01:58

I would like to show a div when someone hovers over an element, but I would like to do this in CSS and not JavaScript. Do you know how this can be ach

相关标签:
13条回答
  • 2020-11-22 02:33

    This answer doesn't require that you know the what type of display (inline, etc.) the hideable element is supposed to be when being shown:

    .hoverable:not(:hover) + .show-on-hover {
        display: none;
    }
    <a class="hoverable">Hover over me!</a>
    <div class="show-on-hover">I'm a block element.</div>
    
    <hr />
    
    <a class="hoverable">Hover over me also!</a>
    <span class="show-on-hover">I'm an inline element.</span>

    This uses the adjacent sibling selector and the not selector.

    0 讨论(0)
提交回复
热议问题