Adding custom styles to CKEditor

匿名 (未验证) 提交于 2019-12-03 01:12:01

问题:

I recently added CKEditor to my app and I would like to include my own CSS stylesheets within the editor so that I can select them within the editor.

How do I accomplish this? My code so far looks like this:

 

回答1:

Please look at @metavida answer for a better answer than this

 

Though if you're using this in more than one place it'd be best to look at putting this into the stylescombo\styles\default.js file and updating your config.js file accordingly as per api.



回答2:

 

You can also read the full documentation of the stylesSet.add syntax:



回答3:

This works for me

CKEDITOR.addCss('body{background:blue;}'); 


回答4:

As has already been mentioned, there is a page explaining how to set up a set of custom styles. What the little gem hidden on that page (and not really clear) is that rather than creating a named set of styles, you can define the styles inline in your configuration, like this:

    stylesSet : [     {         name : 'Green Title',         element : 'h3',         styles :         {             'color' : 'Green'         }     } ], 


回答5:

Little late to the party here, but the default styles are in _source/plugins/styles/styles/default.js. You could use that as your style config and add styles and it would effectively be appending.



回答6:

The best way is to use this plugin: http://ckeditor.com/addon/stylesheetparser

Paste it inside the 'ckeditor/plugins' directory, then include something like this in your 'ckeditor/config.js':

config.extraPlugins = 'stylesheetparser'; config.contentsCss = '/css/inline-text-styles.css'; config.stylesSet = []; 

Where '/css/inline-text-styles.css' is a path to your own css folder in your webroot, outside of ckeditor. That saves you having to mix css with javascript.



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