简体   繁体   中英

Difference between HTML “overflow : auto” and “overflow : scroll”

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

Could someone please explain me whats the difference between them?

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

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

overflow: scroll will 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: auto is very similar, but the scrollbars only appear when the content is overflowing.

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

Take a look at CSS Tricks .

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.

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

overflow: scroll will show both horizontal and vertical scrollbar even when you don't need one or other. while, overflow: auto will show the scrollbar which your div needs. so basically auto will help you to get rid of both scollbar. Here is more of that:

https://css-tricks.com/the-css-overflow-property/

In Windows, overflow: scroll will always show the scrollbar and overflow: auto will show the scrollbar only if the content is overflowing. In macOS, the overflow: scroll and overflow: auto will always show the scrollbar if the content is overflowing. Tested in Chrome. I highly recommend using overflow: auto as it works the same way and does not generate problems in windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM