Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust font size depending on which font is used from a font stack

I'm using one of the new google api fonts for a heading on a site. It's Yannone Kaffeesatz and is quite a condensed typeface.

My font stack is as follows:

    font-family: 'Yanone Kaffeesatz', arial, serif;

This is fine when the Yannone Kaffeesatz font renders, but if it doesn't, Arial is much more open and the heading spans over two lines.

My question is:

Is it possible to use a different font-size depending on which font is rendered on the page?

Ideally supported across a multitude of browsers.

Thanks

Tom

like image 630
TDH Avatar asked Nov 07 '10 16:11

TDH


People also ask

What is font stacking?

A font stack is a list of fonts and font keywords used to let a browser know our preferred and fallback fonts.

What is font-size-adjust in CSS?

The font-size-adjust CSS property sets the size of lower-case letters relative to the current font size (which defines the size of upper-case letters).

When using a font stack to declare the font-family in what order should?

A font stack is a list of fonts in the CSS font-family declaration. The fonts are listed in order of preference that you would like them to appear in case of a problem, such as a font not loading.


1 Answers

Nope, this is not possible. It is complex and difficult to find out the actual used font from a font-family list even in JavaScript - it's impossible in pure CSS.

If you want to go the JavaScript route, here is a link to a clever method to detect the actual font-family in JavaScript.

Once you know the font used, it's easy to adjust element.style.letterSpacing to the required amount.

like image 83
Pekka Avatar answered Sep 19 '22 21:09

Pekka