Dave Woods - HTML, CSS, Web Design

Personal Website of a Web Designer

Image of WWW painted on a road

Subscribe in a reader technorati fav

Meta:


Flickr:



Blog Advertising - Get Paid to Blog
Dave Woods is a 28 year old freelance web designer from the UK. He specialises in HTML & CSS using the latest web standards to ensure cross browser compliance, search engine friendly, usable and accessible websites are of the highest quality.

Firefox scrollbar fix

Published by Dave | Filed under Web Standards, CSS, Hints and Tips

If you’ve ever developed a site which is centrally aligned and only requires a vertical scrollbar on some pages then you’ll have experienced the problem in Firefox where the page appears to jump to allow for the appearance and disappearance between pages.

However, there is a fix which can force the scrollbar to appear all the time which prevents the jumping of the page and it’s really simple to implement.


By applying the following code to your CSS, you’ll force a scrollbar to appear which can scroll approximately 7 or 8 pixels by default but will also allow for the content to scroll should it exceed the bottom of the window.

html {
min-height: 101%;
}

Why 101%

I initially use 100.1% as this certainly works in Firefox and only applies a 1px scrollbar by default which is much nicer. However, after testing this on all browsers, it appears as though Opera doesn’t support the decimal place and therefore this has to be rounded up to 100.1% to force the scrollbar in Opera.

It all depends which is more important to you as a developer and the client though. Maybe a 1px scroll would be better and to leave the page jumping slightly in Opera or maybe complete consistency across browsers is more important in which case, the 7 or 8px scroll in Firefox can be ignored.

Either way, applying a min-height on the html element that’s greater than 100% will force a scrollbar and fix this annoying behaviour.

Note: Internet Explorer displays a scrollbar by default and is therefore not affected by this Firefox fix.


[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google]
October 15th, 2007


10 Responses to “Firefox scrollbar fix”

  1. Edwin Siebel Says:

    Why not use:

    html {
    overflow: -moz-scrollbars-vertical; /* Always show scrollbar */
    }

    So much easier.

    Edwin

  2. Dave Says:

    Hi Edwin, thanks for the suggestion however that won’t solve the problem for Opera and is actually invalid CSS code.

    However, it did give me another idea as the valid CSS for this is overflow-y which works for Firefox and in other browsers which is a great solution and much nicer than the 101% height fix I’ve been using :)

    html {
    overflow-y: scroll;
    }

  3. Peter Johnson Says:

    -moz- styles are not actually invalid. Refer to section 2.3 of the following W3C document:
    http://www.w3.org/TR/2007/WD-css-beijing-20071019/

  4. Unique Numbers in CSS | Play Work Play Studio Says:

    […] Like the number before it, 101% is also used on the height property. This is commonly used to deal with Firefox’s behavior of adding/hiding its vertical scrollbar depending on whether the page is taller than the viewport or not. This behavior gives the effect of inconsistencies between pages depending on their height. Using this technique, Firefox is forced to always display the scroll regardless of page height. […]

  5. Peter Says:

    Tried both 101% and overflow-y: scroll; both work fine.

    I’ll leave it with second option on site.

    Nice fix thanks again.

  6. J Says:

    Searched for “force scroll html” and found this. Thanks!

  7. Aaron Says:

    Thanks for this post! The only difference I notice between the two approaches, min-height and overflow-y is that min-height onload will create a scrollbar 100% in length of its scrolling channel then reduce to its true size, and the overflow-y does not. I’m viewing this in firefox. None of this really matters, both fixes work, I’m prefering overflow-y for the non-resizing scrollbar.

  8. Fenix Says:

    Both methods worked for me but

    html {
    overflow-y: scroll;
    }

    does not validate in CSS level 2.1 so I went for the first option , which validates no problem.

    Thanks for the help!

  9. Reegan Says:

    Hi Dave thanks for the help it works. but it show doubel scroll in IE6 & IE7 wat to do pls help me :(

  10. Nitecore Says:

    I keep hoping that Firefox will address this issue in the next version, but it never seems to happen.

    Firefox is great to use, but a pain to design for.

Leave a Comment