How to set default font-size on CKEditor

隐身守侯 提交于 2019-11-29 08:44:47
EWPDesign

I hope the answers above help some people. They did not help me and here's why. Using firebug, I could see that about:blank had a default font for the p tag which overrode my setting in the contents.css file as mention above. Here's what I did to fix it. I added a p to the body tag and added !important to the font-family and font-size lines:

body, p {
    /* Font */
    font-family: Arial, Verdana, sans-serif !important;
    font-size: 12px !important;

    /* Text color */
    color: #000;

    /* Remove the background color to make it transparent */
    background-color: #fff;
}

Worked great! I hope this helps.

You can use the javascript API to add some style to a CKEditor instance

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.stylesSet.html

// The set of styles for the Styles combo
CKEDITOR.stylesSet.add( 'default',
[
    // Block Styles
    { name : 'Blue Title'       , element : 'h3', styles : { 'color' : 'Blue' } },
    { name : 'Red Title'        , element : 'h3', styles : { 'color' : 'Red' } },

    // Inline Styles
    { name : 'Marker: Yellow'   , element : 'span', styles : { 'background-color' : 'Yellow' } },
    { name : 'Marker: Green'    , element : 'span', styles : { 'background-color' : 'Lime' } },

    // Object Styles
    {
        name : 'Image on Left',
        element : 'img',
        attributes :
        {
            'style' : 'padding: 5px; margin-right: 5px',
            'border' : '2',
            'align' : 'left'
        }
    }
 ]);
Pachelbel

Let us say you want to use Verdana as the default font. Here is what you can do:

  1. Open contents.css and change the font:

    font-family: Verdana;

  2. In the application/page where the output will be published, add this style:

    <style> .entry-content {font-family: Tahoma;} </style>

That's it! Now you have changed the default font successfully.

I hope this helps. Here are a few things I have noticed.

First, I really need to keep on refreshing to see the new changes appear. I edited the .css file named contents.css inside the /ckeditor/ directory, you can change these:

color: #000000;
background-color: #ffffff;
font-size:24px; /* Just added this */

I also noticed you can edit the file named editor.css inside the /ckeditor/skins/kama/editor.css directory. You can change 'kama' to whatever skin you are using. Now you can edit the .cke_contents parts.

Seems also like contents.css will overwrite what you have done in editor.css. Hope this helps guys.

Make sure you refresh or clear cache to see if any changes are being made.

Applying styles in text-area of CKEditor in page example :

CKEDITOR.replace('textarea', {contentsCss: ".cke_editable{font-size: 18px; font-family:muna;}" , font_defaultLabel : 'Muna' , fontSize_defaultLabel : '18px'});

Here to setting default font-size for CKEditor:

skins/editor.css

.cke_reset_all,.cke_reset_all *{font:12px}

When inspect the element I typed in the editor, I found it is contents.css file that actually has effects on the font style.

So go the the contents.css file inside the ckeditor directory, make this change:

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