Using only CSS, show div on hover over

后端 未结 13 1107
时光取名叫无心
时光取名叫无心 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:09

    .showme {
      display: none;
    }
    
    .showhim:hover .showme {
      display: block;
    }
    HOVER ME
    hai

    jsfiddle

    Since this answer is popular I think a small explanation is needed. Using this method when you hover on the internal element, it wont disappear. Because the .showme is inside .showhim it will not disappear when you move your mouse between the two lines of text (or whatever it is).

    These are example of quirqs you need to take care of when implementing such behavior.

    It all depends what you need this for. This method is better for a menu style scenario, while Yi Jiang's is better for tooltips.

提交回复
热议问题