由于下面的 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.
关于css - 不需要滚动时移除滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6663502/