views:

1200

answers:

5

When you go to page on my website where there is extra content, the scrollbar appears on the right, but it has a notiable shift to the left for my content. You notice this by clicking home and then hosting and back again on my site (www.ipalaces.org)

How can I account for the browser scrollbar on my pages? Can I make it so the scrollbar is always visible atleast?

My website is www.ipalaces.org, please let me know.

+4  A: 

Well, it depends on the browser.

body {

overflow-y: scroll;
overflow-x: scroll;
overflow: -moz-scrollbars-vertical;

}

Should force the horizontal (overflow-x) and vertical scrollbars (overflow-y) to be displayed. Though I recall that Opera sometimes fails to respect the declaration, unless it's on an element within the <body> (divs and the like).


Edited with regard to @wsanville's, and @BHare's, comment.

David Thomas
This leaves an ugly double scrollbar when it needs it.
BHare
Define 'double scrollbar.' Two scrollbars together on each axis?
David Thomas
You should not apply the overflow properties to both `html` and `body` otherwise you will have two scrollbars! Yuck!
wsanville
@wsanville: ah, so that's what @BHare's comment meant. I agree, that's ugly.
David Thomas
+1  A: 

Make your body 101% tall... this will force the scrollbar to always show up.

body {height:101%}
Joseph Silvashy
That works good, but then there is an annoying 1 pixel downward shift. Is there not a way to make all browsers show the scrollbar but have it disabled if not needed. Like -moz-scrollbars-vertical; but more universal
BHare
html, body { height: 100%; margin-bottom: 1px;}Seems to have lessen the gap, but there is still an annoying gap.
BHare
A: 

Give this a try... I know its ugly but it may be the only way.

#force_scroll { 
width:1em; 
position:absolute; 
top:0; 
bottom:-0.1px; 
z-index:-1; 
}

And then in your HTML somewhere (preferably right before your </body>):

<div id="force_scroll"></div>
Joseph Silvashy
Before my what?? This also does not work.
BHare
-0.1px is not a valid measurment. Even so, using -1px or -0.1em still leaves the same effect as margin-bottom: 1px;The page can still scroll down 1 pixel.
BHare
@Brian, see the edit. Originally the `</body>` wasn't escaped/marked as code. So it wasn't rendered on page. I realise it's probably too late to be useful though.
David Thomas
+1  A: 
body {
   overflow: scroll;
}

I had the same problem with even the newest Firefox (3.5). The overflow function saved my life!

joe
+1  A: 

I've tested this on IE6, IE7, IE8, Firefox 3, and Chrome, and the simple way to have a vertical scroll bar always visible is simply:

html { overflow-y: scroll; } 
wsanville