Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping a web-page centered when browser scroll bar appears and disappears

Tags:

javascript

css

Very basic question I think. I have a website where some pages are likely to fit within the viewable vertical area of the browser, and others won't (a lot of sites must be like this).

When users browse from one page to another on the desktop browser, the vertical scroll-bar therefore appears and disappears, depending on the page. The affect, is that the nicely centered page keeps on shifting by the width of the scroll-bar when the user just selects another navigation link - what's the easiest way to stop this happening, without making all my web pages the same height?

Second part - why do desktop browser not just reserve the vertical scroll-bar area, perhaps there's a way to force them?

like image 757
pgfearo Avatar asked Sep 14 '11 20:09

pgfearo


1 Answers

This does it (doesn't work with IE6):

body { overflow-y: scroll; }

If you also want to always show the horizontal scroll bar, use this:

body { overflow: scroll; }
like image 56
Alec Gorge Avatar answered Nov 09 '22 15:11

Alec Gorge