PDA

View Full Version : Forcing a Scrollbar on the page


ksduded
04-24-2008, 03:37 PM
I want to force a scrollbar on the page even if there is no scrolling needed. I have a fixed background and it shifts to the center if there is no scroll bar present leaving black space on the sides.

Sagacious
04-24-2008, 03:44 PM
html { overflow-y: scroll; }
html { overflow: -moz-scrollbars-vertical; }

I am assuming it's Firefox that isn't showing your vertial scrollbar unless it's needed, this CSS should fix it.

abduraooft
04-24-2008, 03:44 PM
Could you post a link so that we can find out some alternatives. Personally, I don't like scroll bars, if there is no enough content.

Jazzo
04-24-2008, 03:45 PM
In CSS, whatever element it is, do:

element
{
overflow:scroll;
}


that should work.

If it's the whole doc you want to scroll, do


body
{
overflow:scroll;
}

jcdevelopment
04-24-2008, 03:46 PM
try this and put it in the css


body {
overflow:scroll;
}


see if that works

ksduded
04-24-2008, 03:54 PM
just putting this in worked

html { overflow: -moz-scrollbars-vertical; }

Apostropartheid
04-24-2008, 04:19 PM
In Mozilla, yes. Not in IE. Or Opera. Or Safari. Or any other browser. It would be a lot better, as abdura mentioned, to post your code and let us find an alternative as there is no consistent way to get it cross browser without overflow:scroll (which activates a nasty bottom scrollbar.)

Sagacious
04-24-2008, 04:29 PM
IE always shows a vertical scrollbar - so that's two browsers down.

abduraooft
04-24-2008, 04:30 PM
In Mozilla, yes. Not in IE. Or Opera. Or Safari. Or any other browser. It would be a lot better, as abdura mentioned, to post your code and let us find an alternative as there is no consistent way to get it cross browser without overflow:scroll (which activates a nasty bottom scrollbar.)
I think we can selectively use it like overflow-x:hidden; ovenrflow-y:scroll;, but I still don't know the purpose of all this.
I have a fixed background and it shifts to the center if there is no scroll bar present leaving black space on the sides.

Sagacious
04-24-2008, 04:37 PM
html { height: 100%; margin-bottom: 1px; }

This is a multi-browser solution - though I haven't got a copy of Opera here to test on that.

Apostropartheid
04-24-2008, 05:26 PM
overflow-x and overflow-y are only recognized by IE & Firefox.

Tinister
04-24-2008, 06:03 PM
Nah, Safari 3 recognizes them as well.

Apostropartheid
04-24-2008, 07:42 PM
Either way, they're both invalid (in CSS2.1)—although I guess you can validate it as CSS3, whose profile is subject to change.