问题描述
CSS有规则允许我们使用自定义字体。
CSS has a @font-face
rule which allows us to "use" custom fonts.
JavaScript是否具有此功能?
Does JavaScript have this functionality?
更具体地说,是否可以在不使用CSS @ font-face
规则的情况下使用自定义字体?
More specifically, is it possible to "use" custom fonts without using the CSS @font-face
rule?
推荐答案
除了使用 @ font-face $外,没有办法让浏览器从网络加载字体c $ c>规则。您可以从理论上从JavaScript创建
@ font-face
规则,而无需使用 document.write
(或 document.createElement(style)
etc),如果您使用;但我现在不会指望在任何浏览器中实现。
There is no way to cause the browser to load a font from the network other than with a @font-face
rule. You could theoretically create that @font-face
rule from JavaScript without having to use document.write
(or document.createElement("style")
etc), if instead you used the CSS Object Model; but I wouldn't count on that to be implemented in any browser at the moment.
这篇关于如何使用JavaScript导入字体文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!