views:

2192

answers:

4

I have a CKEditor used to edit a text in a web-page.

In the web-page, the text renders in its context and therefore follows the page CSS formatting.

My question is how to tell CKEditor to apply a CSS style-sheet to the editor rendering ? Without of course changing the generated source ?

My code :

<textarea class="ActuContent" name="actu-content" cols="100" rows="20">my content></textarea>
<script type="text/javascript">
        window.onload = function()
        {
                CKEDITOR.replace( 'actu-content' );
        };
</script>

and my CSS :

.ActuContent{
    padding:10px 10px 10px 10px;
    color:#416a8b;
    font-size:1.6em;
}

And my CKEditor Config.js file only contains the toolbar config.

CKeditor does not apply the settings of ".ActuContent" to its rendering ...

+1  A: 

CKEditor uses a DIV with normal HTML elements to represent the text you're editing. Just have a look at the content of this DIV and write a appropriate style sheet.

Of course, this only works if you don't modify the output of CKEditor before you render it.

Aaron Digulla
Thanks, I try this right now.
Jalil
I don't understand how to apply like you said. I update my question to put some code in it ...
Jalil
Edited my question to put some code. Can you explain your idea ?
Jalil
In fact, I don't understand how you "have a look at the content of this `DIV` ?
Jalil
In the HTML that your browser displays, there is a DIV in the place where your `textarea` was. Use the debug tools of your browser to have a look inside of it. http://stackoverflow.com/questions/1887216/which-tools-do-you-use-to-debug-html-js-in-your-browser/1887218#1887218
Aaron Digulla
You're right ... I can see that my textarea is made invisible and replace my some CKEditor HTML code ...But the content seems to be in an iframe : <iframe style="width:100%;height:100%" frameborder="0" tabindex="-1" allowtransparency="true" src="javascript:void(0)%3B"/>Any idea where I can "follow up" this ?
Jalil
Hm... CHEditor has a method to get the text as HTML. Try http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData
Aaron Digulla
I can see that. But I'm sorry but I still don't see how I can use this to solve my problem ? Could you post some piece of demo code ?
Jalil
When you know which elements CKEditor uses, you can style them. I don't have demo code. But you should also be able to see the contents of the editor somewhere on your server when you "save" it.
Aaron Digulla
No, the content I "save" only contains the basic HTML (and that's what I want it to do).
Jalil
That's what CKEditor uses. You must style this basic HTML. Use the ID of the container to select the content of the editor in your CSS.
Aaron Digulla
+1  A: 

See this posting:

http://stackoverflow.com/questions/1844569/ckeditor-class-or-id-for-editor-body

The solution posted by nemisj will set the class name onto the body of the editor's editable area.

You can do this in an editor onload function. Call this before you call .replace.

CKEDITOR.on( 'instanceReady', function( ev )
     {
         CKEDITOR.instances.e1.document.$.body.className = "foo";
     });
MustStayAnonymous
This seems to me a very elegant solution. Trying it right now.
Jalil
This solution didn't work for me :-(It gave me a Javascript error (Internet Explorer 6 / 8).
Jalil
+1  A: 

I found a very easy way to answer my question :

the content.css file in CKEditor directory !

I only had to put in the style I wanted to be applied inside the Editor :

body {
    color: #416a8b;
    font-family: Arial;
    font-size: 18px;
    font-weight: 400;
   text-align: left;
}

That's all :-)

Jalil
+3  A: 

The actual best answer to this question would be:

CKEDITOR.config.contentsCss = '/mycustom.css'; CKEDITOR.replace('myfield');

Because you probably would like to have different styles in different editors. If you change the main content.css like Jalil did, you would not be able to do that.

Regards, Rene

Rene