简体   繁体   English

当滚动条可见时,停止浏览器调整网站大小

[英]Stop browser from resizing website when scrollbar is visible

In Windows, when the scrollbar is visible it changes the width of the website and makes it appear to 'jump', yet in Mac OSX the scrollbar simply hovers over the website and doesn't change any sizing. 在Windows中,当滚动条可见时,它会更改网站的宽度并使其看起来像“跳跃”,但在Mac OSX中,滚动条只是悬停在网站上,而不会更改任何大小。

Is there any way to force the scrollbar in Windows to act the same? 有什么方法可以强制Windows中的滚动条执行相同的操作?

I don't believe you can cause the scrollbar to overlay the site, but you can force it to always be visible by setting ( demo ): 我不相信您可以使滚动条覆盖网站,但是可以通过设置( demo )强制使其始终可见:

body{
   overflow-y:scroll;
}

This is on the assumption it is your body element that requires scrolling, alternatively simply set it on the element representing the scrollable viewport. 假设是您的body元素需要滚动,或者将其简单地设置在表示可滚动视口的元素上。

More on overflow-y from MDN 有关MDN overflow-y更多信息

The overflow-y CSS property specifies whether to clip content, render a scroll bar, or display overflow content of a block-level element, when it overflows at the top and bottom edges. overflow-y CSS属性指定当它在顶部和底部边缘溢出时是剪切内容,渲染滚动条还是显示块级元素的溢出内容。

scroll The content is clipped and desktop browsers use scrollbars, whether or not any content is clipped. 滚动裁剪内容,并且桌面浏览器使用滚动条,无论是否裁剪任何内容。 This avoids any problem with scrollbars appearing and disappearing in a dynamic environment. 这避免了滚动条在动态环境中出现和消失的任何问题。 Printers may print overflowing content. 打印机可能会打印溢出的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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