Date Added: Tuesday 24th of February 2009 » Section: Web Development Tutorials

CSS: Horizontal Centering Jumps in Firefox

This is one of those situation i think most developers find themselves running into somewhere down the line. You've created you CSS template using margin:0 auto and everything looks great in the different versions of IE, Firefox, Oprea, Safari etc but for some reason your centering starts to jump all over the place when you click between various pages in Firefox. What's going on here then?...

The answer is quite simply, some browsers like Firefox don't display vertical scroll bars unless required and as a result your template's centering begins to jump around (16px to be exact) when you navigate between a page that has a height that requires scrollbars and one that doesn't. Its obvious now, i hear you cry! Don't worry, i did the same... Doh!

The Solution to Firefox Centering Issue

Don't worry there's a simple solution to this centering and as usual, CSS comes to the rescue. The solution is to force vertical scrollbars.

There's actually a few different ways to fix this scrollbar issue but here's my favourite:

html {
	overflow-y: scroll;
}

Last time i checked this centering fix worked in Firefox, Safari, IE6 and Opera.

Related Tutorials:

Font Size: decrease the font size increase the font size
:

Random Photographs

Web Development Tips & Tricks

Web Development RSS Feed

God Bless The Internet

Web Development RSS Feed

The Fight Club Polls

Who'd win in a fight between Rambo and Rocky?

Rambo vs Rocky
Rambo
Rocky

Ramboscore 63%
Rockyscore 36%
247 votes so far...

Platform and Web Standards: W3C HTML 4.01 Standards W3C CSS 2.1 Standards Powered by PHP Powered by MYSQL RSS Valid Recommend Firefox Page copy protected against web site content infringement by Copyscape