Setting font-size and font-family in CKEditor

牧云@^-^@ 提交于 2019-12-11 03:49:27

问题


I am working with ckeditor

I want to ask how can we set the font-family and font-size in this plugin, I have tried using

CKEDITOR.config.font_defaultLabel = 'Arial';
CKEDITOR.config.fontSize_defaultLabel = '12px';

but these commands just change the front-end (font name and size)

Whats the way out?


回答1:


The most future-proof method(1) is to override the default CSS styles for CKEditor content that you want to change in a separate file, added to your editor configuration through the config.contentsCss option.

See the working sample for this scenario in the CKEditor SDK: http://sdk.ckeditor.com/samples/classic.html

Scroll down to the "Classic Editor with Custom Styles" sample there; you can download the exact source code of this solution in the "Get Sample Source Code" section on the sample page. In this case the custom font and other styles were defined in a separate classic.css file which is then provided to the editor instance configuration with:

<script>
    CKEDITOR.replace( 'myeditor', {
        /* Default CKEditor styles are included as well to avoid copying default styles. */
        contentsCss: [ 'contents.css', 'classic.css' ]
    } );
</script>

Do remember that it is only valid for classic editor as in inline editor content styles are the same as the page styles, so all content styling comes directly from the page stylesheets.

(1) This method is better than modifying the default contents.css file because you don't risk overwriting your changes when you upgrade CKEditor.




回答2:


If you are using the classic editor, check the contents.css file in the root folder of CKEditor. You can change the styles, including fonts, for all HTML elements, also for the <body> element (the editing area).

Instead of modyfying the default config.css you may specify additional CSS files to be loaded with config.contentsCss, this will save you a headache with future upgrades. See Anna's comment.



来源:https://stackoverflow.com/questions/27155789/setting-font-size-and-font-family-in-ckeditor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!