我有一个JS代码:
fontCode += "*{font-family: " + sendFont.f + ", fontAwesome !important;}";
我想通过 css font-face
添加一些字体
所以我将 font-face
代码添加到一个名为 font-face.css
的 css 文件中
然后我尝试将 font-face.css
文件包含到 JS 中,我将 js 代码更改为:
fontCode += "@import url('font-face.css'); *{font-family: " + sendFont.f + ", fontAwesome !important;}";
但是没有成功!我不知道如何在我的 js 文件中使用 css font-face
。
最佳答案
WebFont.load({
google: {
families: ['Droid Sans', 'Droid Serif']
}
});
或
var newStyle = document.createElement('style');
newStyle.appendChild(document.createTextNode("\
@font-face {\
font-family: " + yourFontName + ";\
src: url('" + yourFontURL + "') format('yourFontFormat');\
}\
"));
document.head.appendChild(newStyle);
提问前请先搜索
关于javascript - 如何在javascript文件中使用css代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51498933/