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

风流意气都作罢 提交于 2019-11-29 13:42:02
Pekka 웃

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!