在CSS中指定后备字体大小? [英] Specify fallback font sizes in CSS?

查看:165
本文介绍了在CSS中指定后备字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以为CSS中的回退字体指定不同的字体大小?我想做这样的事情(显然不行):

Is there any way to specify different font sizes for fallback fonts in CSS? I want to do something like this (which obviously does not work):


div {
    font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
    font-size: 20px, 18px, 18px, 18px;
}

这个想法是,如果用户安装它,Arial Narrow将显示为20px;如果没有,浏览器会回到Arial在18px,然后Helvetica在18px等。

The idea being that Arial Narrow would display at 20px if the user has it installed; if not, the browser would fall back to Arial at 18px, then Helvetica at 18px, etc.

或者,我可以使用JS实现类似的效果吗? >

Or, could I use JS to achieve a similar effect?

推荐答案

我明白你想要什么,但我认为你的问题的答案是不,这不能在CSS

I understand what you want, but I think the answer to your question is "No, this can't be done in CSS", at least not in CSS2 afaik.

希望有人能证明我的错误,因为我也想这样:D

Hoping someone can prove me wrong, 'cause i want this too :D

我想JS可以完成这一点,至少达到一些点。不知道是否有是这个字体安装?方法在JS,但你可以能够做一些有根据的猜测基于操作系统等。没有遇到困难。

I suppose JS can accomplish this, at least up to some point. Not sure if there is a "is this font installed?" method in JS, but you may be able to make some educated guesses based on OS and such. Got no experience there sorry.

编辑:有些快速搜索提供了一些聪明的JS技巧,虽然我还没有尝试过。例如。
http://remysharp.com/2008/07/08/how-to-detect-if-a-font-is-installed-only-using-javascript/

some quick googling does provide a few clever JS tricks, though I haven't tried them yet. E.g. http://remysharp.com/2008/07/08/how-to-detect-if-a-font-is-installed-only-using-javascript/

另一个编辑,经过一些更多的搜索:
我是由有人应该提出它触发:D。看来CSS3规范有font-size-adjust,这可能在这里使用。但是,在Firefox以外的浏览器中的支持在写这个时可能不是最佳的。以下是该资源上的W3字:
http:// www.w3.org/TR/WD-font/#font-size-adjust

Another edit, after some more searching: I was triggered by the "someone should propose it" :D. It seems CSS3 spec has the "font-size-adjust", which may be of use here. However, support in browsers other than Firefox may not be optimal at the time I write this. Here's the W3 word on that property: http://www.w3.org/TR/WD-font/#font-size-adjust

这篇关于在CSS中指定后备字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆