Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor add CSS styling to Preview and Editor

Is it possible to add CSS to style the Editor text as well as the Preview?

The CMS has a different set of CSS files from the public part of the website and I want the editor to try (at least) and reflect the way it would look in the site.

For example, all tags with a class of .floatLeft{float:left;margin:0 10px 10px 0;} I want to look the same in the Editor.

Thank you.

like image 759
Francisc Avatar asked Aug 31 '10 10:08

Francisc


People also ask

How to add Css in CKEditor?

var editor = CKEDITOR. replace( 'editor' ); // Add dynamic css text to be used by the editing area. editor. addCss( 'body { background-color: grey; }' );

What is CKEditor replace?

Ckeditor 4 allows you to replace multiple textareas with editors based on classname: CKEDITOR.

How do I change CKEditor height?

The CKEDITOR. config. height option sets the height of the editing area with CKEditor 4 content — it does not include the toolbar or the bottom bar. This configuration option accepts an integer (to denote a value in pixels) or any CSS-defined length unit except percent ( % ) values which are not supported.


2 Answers

Setup CKEDITOR.config.contentsCss variable. CKEDITOR.config.bodyClass and CKEDITOR.config.bodyId could help too. These are only options you have (i think).

like image 62
Anpher Avatar answered Oct 09 '22 19:10

Anpher


To be more exact, you can edit your ckeditor/plugins/styles/styles/default.js and add in files something like { name : 'FloatLeft', element : 'span', attributes : { 'class' : 'floatleft' }}.

Then you add to your ckeditor/contents.css (if you decided to use the editor style) or in your own style.css the class declaration .floatLeft{float:left;margin:0 10px 10px 0;}

Do not forget to clear the browser cache after saving :)

Enjoy

like image 25
Ravaka Avatar answered Oct 09 '22 21:10

Ravaka