Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. This prevents the user from accessing content. I've set my body width to 500px and set the navbar to 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.

like image 726
Nickel Avatar asked Dec 13 '12 16:12

Nickel


People also ask

How do you make the scrollbar visible in CSS?

Make sure overflow is set to "scroll" not "auto." With that said, in OS X Lion, overflow set to "scroll" behaves more like auto in that scrollbars will still only show when being used.

How do I force scrollbar to show in HTML?

To show the scrollbars always on the webpage, use overflow: scroll Property. It will add both horizontal and vertical scrollbars to the webpage. To add only horizontal scrollbar use overflow-x: scroll property and for vertical scrollbar use overflow-y: scroll property.

How do I make the scrollbar show in all browsers?

scrollbar is not a CSS standard. In Chrome or Safari (WebKit) you can use the extension prefixed by -webkit- Read more here. FireFox doesn't support scrollbar styling. So probably you can support this effect in IE and WebKit browsers only, or use JavaScript libraries as Iwo Kucharski said.

How do I show the scroll bar only when needed CSS?

Use overflow: auto . Scrollbars will only appear when needed. (Sidenote, you can also specify for only the x, or y scrollbar: overflow-x: auto and overflow-y: auto ).


2 Answers

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.

like image 168
Ardeshir P. Avatar answered Sep 28 '22 15:09

Ardeshir P.


You can set the height or width of the body/element to 100.1% depending on which direction and element you want to have scrollable.

like image 21
span Avatar answered Sep 28 '22 15:09

span