如何在 CKEditor 中将 google-font 设置为默认字体?

low*_*nts 3 html css rich-text-editor ckeditor google-font-api

我想在我的 CKEditor 中使用“Open Sans”作为默认字体,但不知道如何使用。
我正在使用 CKEditor 4.4.5 full

我已经在我的 html 头中包含了字体:

<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
Run Code Online (Sandbox Code Playgroud)


然后我尝试通过更改contents.css中的CSS来更改CKEditor的默认字体:

body
{
    /* Font */
    font-family: "Open Sans";
    font-size: 18px;
}
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。

我还尝试在我的 Javascript 中设置它:

CKEDITOR.config.font_names = "Open Sans;";
CKEDITOR.config.font_defaultLabel = 'Open Sans';
Run Code Online (Sandbox Code Playgroud)

但这似乎只影响“字体”工具栏的显示,而不是样式本身。


注意:当我使用“ckeditor-gwf-plugin”时,我可以使用“Open Sans”,但这也无助于我将其设置为默认字体。

谢谢你的帮助 !

all*_*aps 5

我假设您需要为 CKEditor 的内容区域设置样式?比您需要创建一个 css 文件并将其添加到您的 CKEditor 配置中,如下所示:

contentsCss : '/path/to/style.css',
Run Code Online (Sandbox Code Playgroud)

在 style.css 中:

@import url(http://fonts.googleapis.com/css?family=Open+Sans);
body, p { font-family: 'Open Sans', sans-serif; }
Run Code Online (Sandbox Code Playgroud)

确保/path/to/style.css负载。使用您的浏览器开发人员工具。还要设置适当的选择器:body,p用于文本,也许h1, h2, h3.

大多数情况下,此文件中的样式与您的 Web 应用程序中使用的排版样式相同。