CSS :hover works only when mouse moves

前端 未结 3 1511
粉色の甜心
粉色の甜心 2021-01-04 08:39

I created a very basic sample:

HTML

CSS

#bla {         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 08:49

    When you set display to none the image takes up no space meaining there is nowhere to hover over.

    I would set the background-image in you css to rgba(0 0 0 0); making it invisible but still in the dom. You can then change your javascript to

    setTimeout(function() {
         document.getElementById('bla').style.backgroundColor="green";
    },2000);
    

    http://jsfiddle.net/euT7k/3

提交回复
热议问题