Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compensate for Vertical Scrollbar when it is not yet present

Maybe this is an easy fix, but it has been driving me crazy for a long time so I finally decided to see if a solution exists.

Simply put, I center most of my web pages within wide view-ports.

Example, a view-port might be capable of 1028px and I want my page width to only be 960px.

So my css looks like this:

#pageWrapper { /* page width is 960 pixels */
    margin:0 auto;
    width:960px;
}

No problem with that.

The problem comes in when I start a dynamic page that is shorter than the height of the and then my page expands (via jQuery slideOut, etc.) below the bottom of the screen and causes the vertical scrollbar to appear.

It ends up making the page flicker left during the slideOut and then flicker right during slideIn.

Is there some way through css to force a 20px right margin and still take advantage of margin:0 auto; ?

Thanks.

like image 589
H. Ferrence Avatar asked Mar 10 '12 22:03

H. Ferrence


People also ask

How do I set my vertical scrollbar?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

How do I know if my vertical scrollbar is visible?

use it like this, $('#my_div1'). hasScrollBar(); // returns true if there's a `vertical` scrollbar, false otherwise..

How do you hide the vertical scrollbar when not needed?

To hide the vertical scrollbar and prevent vertical scrolling, use overflow-y: hidden like so: HTML. CSS.

How do I make my scrollbar visible?

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.


1 Answers

When the contents of the page no longer fit vertically, the browser adds a scrollbar to the right side of the window. This changes the available width in the browser window, so any content that is either centered or positioned relative to the right side of the window will move left a bit. This is very common.

There are a number of ways to control this, but the most common is to either make it so you always have a scrollbar or never have a scrollbar by controlling the overflow-y property on the window.

Setting overflow-y: scroll will force the scrollbars to always be there.

Setting overflow-y: hidden will force there to never be scrollbars.

like image 153
jacktheripper Avatar answered Sep 28 '22 09:09

jacktheripper