HTML“溢出:自动”和“溢出:滚动”之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6689412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:33:21  来源:igfitidea点击:

Difference between HTML "overflow : auto" and "overflow : scroll"

htmlcss

提问by GirishK

When I was studying the overflowproperty's values, I came across these two values: autoand scroll, which adds scrollbar(s) if the content overflows the element.

当我研究overflow属性的值时,我遇到了这两个值:autoand scroll,如果内容溢出元素,它会添加滚动条。

Could someone please explain me whats the difference between them?

有人可以解释一下它们之间有什么区别吗?

回答by Johan Davidsson

Auto will only show a scrollbar when any content is clipped.

Auto 只会在任何内容被剪切时显示滚动条。

Scroll will however always show the scrollbar even if all content fits and you cant scroll it.

然而,即使所有内容都适合并且您无法滚动它,Scroll 也会始终显示滚动条。

回答by James Allardice

overflow: scrollwill hide all overflowing content and cause scroll bars to appear on the element in question. If the content does not overflow, the scrollbars will still be visible, but disabled.

overflow: scroll将隐藏所有溢出的内容并导致滚动条出现在相关元素上。如果内容没有溢出,滚动条仍然可见,但被禁用。

overflow: autois very similar, but the scrollbars only appear when the content is overflowing.

overflow: auto非常相似,但滚动条仅在内容溢出时出现。

There is a similar explanation of this here, with some screenshots to illustrate the point.

有这样一个类似的解释在这里,有一些截图来说明这一点。

回答by samir chauhan

Take a look at CSS Tricks.

看看CSS 技巧

Auto will show scrollbar if and only if the content overflows; but scroll will always show the scrollbar, whether the content is overflowing or not.

当且仅当内容溢出时,Auto 才会显示滚动条;但是 scroll 将始终显示滚动条,无论内容是否溢出。

回答by Kira

Adding a point to the answer, Overflow:autonot worked in IE7 when position of the container is absolute Position relative overflow IE7. But setting Overflow:scrollworks

为答案添加一点,Overflow:auto当容器的位置是绝对位置相对溢出 IE7时,在 IE7 中不起作用。但设置Overflow:scroll有效