简体   繁体   English

用于强制浏览器显示滚动条的CSS

[英]CSS for forcing the browser to display scrollbar

I've written a web application and found that when I resize the page, the browser doesn't display it's own scrollbar as the window shrinks. 我写了一个Web应用程序,发现当我调整页面大小时,浏览器不会显示它自己的滚动条,因为窗口缩小了。 This prevents the user from accessing content. 这可以防止用户访问内容。 I've set my body width to 500px and set the navbar to white-space:nowrap . 我将我的身体宽度设置为500px并将导航栏设置为white-space:nowrap How can I get the browser to recognize that there is content to the right of the screen? 如何让浏览器识别屏幕右侧有内容?

Just to clarify I want the browser's scrollbar and not a scroll bar on any control. 只是为了澄清我想要浏览器的滚动条而不是任何控件上的滚动条。

You can use one of the following depending on whether you want horizontal, vertical, or both scrollbars to be added: 您可以使用以下其中一项,具体取决于您是要添加水平,垂直还是两个滚动条:

body    {overflow-x:scroll;}
body    {overflow-y:scroll;}
body    {overflow:scroll;}

However, I think if you show the content in a section and then do 但是,我认为如果您在一个部分中显示内容然后执行

#id-of_your_div {overflow:scroll;}

So that you add scroll to the div rather than force the browser to show scrollbars, then your page will provide a much better user experience since such scrollbars are easier for users to access. 因此,您可以向div添加滚动而不是强制浏览器显示滚动条,那么您的页面将提供更好的用户体验,因为这样的滚动条更易于用户访问。

您可以将body / element的高度或宽度设置为100.1%,具体取决于您希望可滚动的方向和元素。

Instead of playing with the width, use the code that was intended for this purpose. 不要使用宽度,而是使用专门用于此目的的代码。 The following CSS will force a scroll-bar to be present whether it's needed or not. 无论是否需要,以下CSS都会强制显示滚动条。

for both scroll-bars... 两个滚动条......

body {
    overflow: scroll;
}

or just for a horizontal scroll-bar... 或只是一个水平滚动条......

body {
    overflow-x: scroll;
}

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

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