Always show the vertical scrollbar using CSS
- 20 September, 2011 -
- Client-side -
- Tags : css, javascript, snippet
- 0 Comments
The dynamic nature of today’s webpages results in content being added to and removed from the DOM on-the-fly. By adding content to a short page, your content can suddenly surpass the browser window height, which results in a vertical scrollbar being added. The problem is that this addition causes your content to jump horizontally as well, when the browser creates extra space for the vertical scrollbar. Easiest approach to overcome this, is to make sure that your verticall scrollbar is always in sight.
Here’s a simple CSS rule applied to your HTML, which will ensure that the vertical scrollbar is always on display.
html {
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
overflow-x: auto;
}