For my website I have chosen to use some pretty obscure fonts in my font family. The most well known font (3rd in family) is Century Gothic, which most computers have.
There’s a script on lalit.org that guesses which fonts are available on the user’s machine.
You might be able to use that to see if Century Gothic is being used, and if so, load an extra stylesheet that amends your font sizes.
I think the issue is the relatively tall x-height of Century Gothic. Try using ex
units in your font-size
declaration. ex
units are based on height, unlike em
, px
, and pt
.
Setting the line-height
to a pixel size would also help normalize the height, but would cause problems for users who change the text zoom level in their browser.
Edit: I went back and tested, and ex units don't help. Century Gothic is both taller and wider than the others.
The issue is, the DOM will not allow you to tell which specific font the user has from your listed alternates, and CSS doesn't allow separate font sizes (or adjustments) for each font.
However, JQuery can test the size of a container of text. So, if you provide a hidden element on your page with a known letter in it, you can test the width of that element on the user's browser.
Since the width of that letter will be determined by which font the user has installed, you can compare that width to the width of the same text in your preferred font on your own computer and compute a font size for the user that roughly matches what you intended.
Example code:
<style>
p { font-size: 15pt;
font-family:"Tw Cen MT","Gill Sans","Century Gothic",sans-serif;
}
p#testwidth {
/* Ensure test is invisible and isn't messed up with borders, etc. */
margin:0; padding:0; border:none; color:white; display:inline;
}
</style>
<p>Your text goes here.</p>
<p id="testwidth">m</p>
<script language="Javascript">
window.onload = function() {
// Same as your default CSS for font-size (just the number, not the units)
var desiredFontSize = 15;
// Experiment by testing width when Tw Cen MT *is* available. In pixels.
var expectedWidth = 17;
// width found will depend which font is available
var testedWidth = $('#testwidth').width();
// ratio, rounded to one decimal point
var normalizedFontSize = Math.round(
expectedWidth / testedWidth * desiredFontSize * 10) / 10;
// change the stylesheet to "fix" the font size (in your preferred units)
$('p').css('font-size', normalizedFontSize + 'pt');
}
Four caveats:
If you compose to a vertical rhythm this shouldn't really pose much of a problem.
http://24ways.org/2006/compose-to-a-vertical-rhythm
This is totally overkill, but you could use http://www.lalit.org/lab/javascript-css-font-detect and create a conditional.
I really suggest using something like the first method (vertical rhythm) to make then entire issue irrelevant if at all possible. You'll sleep much better at night.