Adjust font size depending on which font is used from a font stack
Asked Answered
K

2

8

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

Kirchhoff answered 7/11, 2010 at 16:54 Comment(3)
This is a dupe, but I can't find the originalReassure
You can add server based user agent detection, and then serve a different page (or just css). IMO this is the only somewhat elegant solution. Google has a list of browsers and versions which are guaranteed to work. If it's mostly static text you could just use a PNG.Schaub
The original duplicate is probably this one: Changing Body Font-Size based on Font-Family with jQueryLeaved
R
4

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.

Reassure answered 7/11, 2010 at 16:56 Comment(1)
Thanks for your response. I had a feeling this was the case. I may have to re-think my stack. I could possibly do something with an overflow or maybe allow it to gracefully run over multiple lines.Kirchhoff
C
0

One property which slightly changes font size depending on font is font-size-adjust. It's CSS3, only supported by Firefox.

But I don't think you want to tweak the size as much as aspect ratio, making Arial narrow. Squeezing a font (e.g. the letter spacing) becomes ugly quick. Instead, you should start with more condensed fonts in your stack.

http://pieroxy.net/blog/2014/10/11/the_quest_for_a_condensed_web_font.html studies condensed font options in detail. One of the trickier findings there is font-stretch: condensed which e.g. helps access e.g. Arial Narrow on windows (with Office).

Colchester answered 16/3, 2015 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.