Make scrollbars only visible when a Div is hovered over?

后端 未结 10 1978
庸人自扰
庸人自扰 2020-12-02 15:04

I am trying to figure out how to have a scrollable div that only shows its scrollbars when Hovered.

Example is Google Image search, in the image below you can see

10条回答
  •  攒了一身酷
    2020-12-02 15:47

    Answer by @Calvin Froedge is the shortest answer but have an issue also mentioned by @kizu. Due to inconsistent width of the div the div will flick on hover. To solve this issue add minus margin to the right on hover

    #div { 
         overflow:hidden;
         height:whatever px; 
    }
    #div:hover { 
         overflow-y:scroll; 
         margin-right: -15px; // adjust according to scrollbar width  
    }
    

提交回复
热议问题