简体   繁体   English

如何在CKEditor上设置默认字体大小

[英]How to set default font-size on CKEditor

I am having a problem setting a default font-size for a CKEditor Instance. 我在为CKEditor实例设置默认字体大小时遇到​​问题。 I have tried googling but found nothing that answers my question. 我曾尝试使用Google谷歌搜索,但未找到任何答案。

I have a page which takes an input for a website. 我有一个页面,用于输入网站。 There are 3 Editor instances and I have to make the default font-size of the first instance to, say about 20 to 30px. 有3个Editor实例,我必须将第一个实例的默认字体大小设置为20至30像素左右。

I have tried modifying contents.css found inside CKEDITOR folder and changing the font-size there but it affects all the 3 editor instances 我尝试修改在CKEDITOR文件夹中找到的contents.css并更改那里的字体大小,但它会影响所有3个编辑器实例

/*
    Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
    For licensing, see LICENSE.html or http://ckeditor.com/license
    */

body
{
    /* Font */
    font-family: Georgia;
    font-size: 12px;

    /* Text color */
    color: #222;

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

ol,ul,dl
{
    /* IE7: reset rtl list margin. (#7334) */
    *margin-right:0px;
    /* preserved spaces for rtl list item bullets. (#6249)*/
    padding-right:40px;
}

Anybody have been able to figure out how to solve this? 有人能够找出解决方法吗? Any help is very much appreciated!.. 很感谢任何形式的帮助!..

Thank you in advance guys.. 预先谢谢你们..

mhond 蒙德

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. 使用firebug,我可以看到about:blank的p标记具有默认字体,该字体覆盖了我在contents.css文件中的设置,如上所述。 Here's what I did to fix it. 这是我所做的修复程序。 I added ap to the body tag and added !important to the font-family and font-size lines: 我将ap添加到body标签,并在font-family和font-size行中添加!important:

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. 我希望这有帮助。

Let us say you want to use Verdana as the default font. 假设您要使用Verdana作为默认字体。 Here is what you can do: 您可以执行以下操作:

  1. Open contents.css and change the font: 打开contents.css并更改字体:

    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: 我在/ ckeditor /目录中编辑了名为contents.css的.css文件,您可以更改以下内容:

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. 我还注意到您可以在/ckeditor/skins/kama/editor.css目录中编辑名为editor.css的文件。 You can change 'kama' to whatever skin you are using. 您可以将“ kama”更改为所用的任何皮肤。 Now you can edit the .cke_contents parts. 现在,您可以编辑.cke_contents部分。

Seems also like contents.css will overwrite what you have done in editor.css. 似乎content.css也将覆盖您在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的文本区域中应用样式:

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

You can use the javascript API to add some style to a CKEditor instance 您可以使用javascript API向CKEditor实例添加一些样式

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.stylesSet.html 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'
        }
    }
 ]);

Here to setting default font-size for CKEditor: 在此处为CKEditor设置默认字体大小:

skins/editor.css skins / editor.css

.cke_reset_all,.cke_reset_all *{font:12px} .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. 在检查我在编辑器中键入的元素时,我发现它实际上是对字体样式有影响的contents.css文件。

So go the the contents.css file inside the ckeditor directory, make this change: 因此,转到ckeditor目录中的contents.css文件,进行以下更改:

.cke_editable{
font-size: 17px;
line-height: 1.6;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM