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

前端 未结 2 471
情歌与酒
情歌与酒 2020-12-20 16:24

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:

相关标签:
2条回答
  • 2020-12-20 16:35

    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).

    0 讨论(0)
  • 2020-12-20 16:37

    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.

    0 讨论(0)
提交回复
热议问题