CSS font-size changes when font-family falls back

css

I want to use a font (gill sans) which renders very small due to a short x-height etc. etc. If I set this at a reasonable size, and then a browser falls back to a more typical font I've specified in the font-family, the fall-back font renders very large – can I set the font-size according to the font the browser is using?

Best Answer

I had the same issue using Calibri (slightly smaller compared to most sans fonts). I ended up doing the following (assumes you have jquery):

  1. Get Remy Sharp's font detection script http://remysharp.com/2008/07/08/how-to-detect-if-a-font-is-installed-only-using-javascript/

  2. Add the following to the $(document).ready() function:

    $(document).ready(function() {
        font.setup();
        if(!font.isInstalled('Calibri'))
            $('body').css('font-size','87.5%');
    });
    

So now if the user doesn't have Calibri we see Arial at 87.5%. This only applied to elements where font-size was not defined/inherited. Wherever font-size is explicitly defined will have to be adjusted as well (maybe add a class to those elements and change the jquery selector to $('.adjustClass')).

Would be nice if you could just do: font:11px Calibri, 10px Arial; - but no such luck :)