Remove scollbar when no need to scroll

核能气质少年 提交于 2019-12-20 01:41:30

问题


I have a div with a scollbar as a result of the CSS below. However, when there is no need to scroll, the bar is still there. There is no slider/arrows, but an emtpy bar is just there. Is there a way to only show the bar if the content overflows? Thanks.

#id{
    overflow: -moz-scrollbars-vertical;
    overflow-x: hidden;
    overflow-y: scroll;
}

回答1:


use

overflow: auto;

then overflow will only be displayed if it actually overflows

auto The behavior of auto isn’t specified in any detail in the CSS2.1 specification. In existing implementations it provides scrollbar(s) when necessary, but it doesn’t show scrollbars unless the content overflows the element’s box.

http://reference.sitepoint.com/css/overflow



来源:https://stackoverflow.com/questions/6663502/remove-scollbar-when-no-need-to-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!