当字体丢失时,让元素上的样式在字体系列中具有继承值是否有效? [英] Is it valid to have the style on an element have an inherit value in the font family for when the font is missing?

查看:23
本文介绍了当字体丢失时,让元素上的样式在字体系列中具有继承值是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个页面,这个 HTML

If I have a page that this HTML

<body style="font-family:Helvetica">
    <span style="font-family:Segue">Hello World</span>
</body>

如果列出的第一个字体在系统上不可用,将span的字体系列设置为Segue,inherit是否有效?

Is it valid to set the font family of the span to Segue, inherit to allow it to inherit the parent font if the first font listed is unavailable on the system?

<body style="font-family:Helvetica">
    <span style="font-family:Segue, inherit">Hello World</span>
</body>

它似乎在浏览器 (Firefox) 中工作,但 Firefox 自己的调试工具说它无效.

It seems to work in the browser (Firefox) but Firefox's own debug tools are saying it's invalid.

也就是说,写font-family:AnyFont,inherit可以吗?

更新:
使用 inherit 不起作用.

现在的问题可能是,当字体不可用时,如何获得一个span来继承字体.

The question may now be, how to get a span to inherit the font when the font is not available.

推荐答案

inherit 独立存在.添加inherit会继承父font-family,不管它自己的font-family是否存在(即你为span声明的font-family即使存在也会被忽略,它只会继承body的字体系列).

inherit exists on it's own. Adding inherit will inherit the parent font-family, whether it's own font-family exists or not (i.e the font-family you declared for span will be ignored even if it exists, it will just inherit the body's font-family).

你可以简单地:

body {
   font-family: Helvetica;
}
span {
   font-family: Segue, Helvetica;
}

那样,它使用Segue,如果它不可用,它会转移到Helvetica.因此,在您的代码中,在 span 样式中,声明您希望它使用的字体,并以逗号分隔.

That way, it uses Segue, if it is not available it shifts to Helvetica. So in your code, in the span style, declare the fonts you want it to fall back to, separated by commas.

这篇关于当字体丢失时,让元素上的样式在字体系列中具有继承值是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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