Goodbye Annoying Little Horizontal Jump

Isn’t it annoying when you have a horizontally centered site that jumps about 20 pixels to the left when you come to a long page that requires scroll bars, and then jumps 20 pixels back to the right when you come to a short page that doesn’t require scroll bars?

IE actually doen’t have this problem, because it has a scroll bar there at all times, whether one is required or not. The trick is to make Firefox and company behave the same – so that a centered page is centered in same spot, no matter how short or long the pages are.

The solution, happily, is quite simple! Simply put this at the top of your CSS file:

html {
min-height:100%;
margin-bottom:1px;
}

And that’s it! IE ignores min-height and Firefox and company have a browser window that is 1 pixel taller than necessary, forcing a vertical scroll bar to be present at all times.

16 Responses to “Goodbye Annoying Little Horizontal Jump”

Leave a Reply