css - 不需要滚动时移除滚动条

标签 css scroll overflow

由于下面的 CSS,我有一个带有滚动条的 div。但是,当不需要滚动时,该栏仍然存在。没有 slider /箭头,但只有一个空栏。有没有办法只在内容溢出时显示栏?谢谢。

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

最佳答案

使用

overflow: auto;

那么只有真正溢出了才会显示overflow

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

关于css - 不需要滚动时移除滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6663502/

相关文章:

html - 将 div 扩展到页面底部(仅限 HTML 和 CSS)

css - 如何摆脱 Bootstrap 面板标题底部的灰线?

HTML, CSS , Table body scrolling with fix header

objective-c - 由于awakeFromNib时间太长而导致应用崩溃

css - 溢出:隐藏属性不适用于伪类前后

html - <ul> 怎么能有均匀的右边距呢?

html - Mailchimp - 如何在图像上方添加可变文本

css - 如何使菜单随页面滚动,但保留 Logo

javascript - 使用 css 或 js 禁用移动浏览器的滚动

jquery - 溢出隐藏的 jQuery 选择器