简体   繁体   English

如何在designMode中使用网络字体?

[英]How to use web fonts in designMode?

I have a text editor that uses designMode and an <iframe> . 我有一个使用designMode<iframe>的文本编辑器。 I'm trying to change the font to a Google Web font. 我正在尝试将字体更改为Google Web字体。 Here's the JavaScript code: 这是JavaScript代码:

function rich(a,b,c) {
    editor.execCommand("styleWithCSS",true,null);
    editor.execCommand(a,b,c);
    editor.focus();
}

HTML for the fonts: 字体的HTML:

<select onchange="if (this.selectedIndex > 0) {rich('FontName',false,this.options[this.selectedIndex].text);}">
            <option selected>Font</option>
            <option>Arial</option>
            <option>Times New Roman</option>
            <option>Courier</option>
            <option>Consolas</option>
            <option>Calibri</option>
            <option>Molle</option>
        </select>

In the <iframe> file, I have this: <iframe>文件中,我有这个:

<link href='https://fonts.googleapis.com/css?family=Molle:400italic' rel='stylesheet' type='text/css'>

I tried to use CSS to change the text into the proper font: 我试图使用CSS将文本更改为正确的字体:

span[style="font-family: Molle"] {
    font-family: 'Molle', cursive;     
}

It doesn't work. 没用 A solution only has to work in Google Chrome. 解决方案仅需在Google Chrome中运行。

The way you're loading the font, only the italic version is loaded. 加载字体的方式仅加载斜体版本。 Therefore the font will only show if you specify italic explicitly in the span's style. 因此,只有在跨度样式中明确指定斜体时,字体才会显示。

font-family:'Molle',sans-serif; font-style:italic;

By the way, can you change the HTML at all? 顺便说一句,您可以完全更改HTML吗? If so, please don't use an inline style and then try to override it with a stylesheet, using the style attribute for a selector. 如果是这样,请不要使用内联样式,然后尝试使用样式表(使用选择器的样式属性)来覆盖它。 Not only does it look ugly and patchy, but it won't work, it won't do anything. 它不仅看起来丑陋且不完整,而且不起作用,也无能为力。 The inline style attribute has a higher specificity than a stylesheet. 内联样式属性比样式表具有更高的特异性。
Either put in the above as the inline style for the span, or give the span a class and use that in the stylesheet to address it. 将上面的内容作为跨度的内联样式,或者给跨度一个类,然后在样式表中使用该类来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM