jQuery 如何更改tinymce中的默认字体大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4427407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:16:00  来源:igfitidea点击:

How to change default font size in tinymce?

jquerytinymcewysiwyg

提问by Mohan Ram

I am using jquery tinymce editor. Default font size is 10. I like to change that default font size. How can i do that,

我正在使用 jquery tinymce 编辑器。默认字体大小为 10。我喜欢更改默认字体大小。我怎样才能做到这一点,

回答by Thariama

You need to use the content_csssetting of tinymce to set a custom css file of your own (make sure this setting points to a valid location of a css file). This file will be inserted in the editor iframes head after all other css settings(files from the core) are inserted there when initialising tinymce - thus all settings you place in your file will overwrite the settings made before (by tinymce).

您需要使用tinymce的content_css设置来设置您自己的自定义 css 文件(确保此设置指向 css 文件的有效位置)。在初始化 tinymce 时将所有其他 css 设置(来自核心的文件)插入到编辑器 iframes 头部之后,该文件将插入到编辑器 iframes 头中 - 因此您放置在文件中的所有设置都将覆盖之前(通过 tinymce)所做的设置。

Example:Setting the default font-size to 11px. Content of a custom css file (i named it content.css in my installation):

示例:将默认字体大小设置为 11px。自定义 css 文件的内容(我在安装中将其命名为 content.css):

body {
    font-family: Verdana,Arial,Helvetica,sans-serif;
    font-size: 11px;
}

How to use this setting:

如何使用此设置:

tinyMCE.init({
 ...
 // you do not need to include it yourself, tinymce will do this for you, 
 // but you will need to give tinymce the location of your css file
 content_css : "http://www.myserver.com/css/content.css", 
     ...
});

回答by Nishad Up

I have used in my project in this way

我以这种方式在我的项目中使用过

tinymce.init({
  selector:"#txt1",
  setup : function(ed)
  {
    ed.on('init', function() 
    {
        this.execCommand("fontName", false, "tahoma");
        this.execCommand("fontSize", false, "12px");
    });
  }  
}); 

This is the better way than just changing property values in 'content.css'

这是比仅更改“content.css”中的属性值更好的方法

回答by Oni Victor

Just add this line to the options

只需将此行添加到选项

content_style: ".mce-content-body {font-size:15px;font-family:Arial,sans-serif;}",

so it looks like this

所以它看起来像这样

tinymce.init({
    selector: "textarea",theme: "modern",width: '100%',min_height:350 ,menubar:false,
     content_style: ".mce-content-body {font-size:15px;font-family:Arial,sans-serif;}",
    browser_spellcheck : true,
    plugins: 
    [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak",
         "searchreplace wordcount visualblocks visualchars insertdatetime media nonbreaking",
         "table contextmenu directionality emoticons paste textcolor responsivefilemanager code"
    ],
   toolbar1: " undo redo preview code | \n\
                 link  bold italic underline | hr | image responsivefilemanager media |unlink anchor  | ",
   image_advtab: true ,

   external_filemanager_path:"/tinymce/filemanager/",
   filemanager_title:"Responsive Filemanager" ,
   relative_urls: false,
    remove_script_host : false,
   external_plugins: { "filemanager" : "/tinymce/filemanager/plugin.min.js"}
 });

回答by KwangKung

<script type="text/javascript">
    tinyMCE.init({
        mode : "textareas",
            setup : function(ed)
            {
                // set the editor font size
                ed.onInit.add(function(ed)
                {
                ed.getBody().style.fontSize = '10px';
                });
            },
            });
</script>

回答by Georg

I'll yust leave this here, with tinyMCE 4 it is now:

我只是把它留在这里,现在有了 tinyMCE 4:

setup : function(ed) {
 ed.on('init', function(ed) {
  ed.target.editorCommands.execCommand("fontName", false, "Calibri");
  ed.target.editorCommands.execCommand("fontSize", false, "11pt");
 });
}

回答by krzyhub

Or just find css file that is used by tinymce and change font-size. For example if You using simple theme then go somewhere like this: js/themes/simple/skins/default/content.cssand there change font-size. Working for me.

或者只是找到 tinymce 使用的 css 文件并更改font-size。例如,如果你使用简单的主题,那么去这样的地方:js/themes/simple/skins/default/content.css然后改变font-size. 为我工作。

回答by mrbangybang

A mix of the answers here worked for me:

这里的混合答案对我有用:

        base_url: '/tinymce',
        suffix: '.min',
        plugins: 'image link lists',
        menubar: false,
        toolbar: 'bold italic underline | bullist numlist | link unlink image | alignleft aligncenter alignright alignjustify',
        branding: false,
        image_uploadtab: true,
        contextmenu_never_use_native: true,
        setup : function(ed) {
            ed.on('init', function(ed) {
                this.getBody().style.fontSize = '12px';
            });
        }

回答by Ben Long

To change the default font size in TinyMCE, you can use content_cssor content_style(or a combination of both) in the initialization script, depending on your use case.

要更改 TinyMCE 中的默认字体大小,您可以在初始化脚本中使用content_csscontent_style(或两者的组合),具体取决于您的用例。

content_csscan be used to load a specific stylesheet.

content_css可用于加载特定的样式表。

For example (where font-size is set on the body element in a file called mycontent.css):

例如(其中 font-size 在名为 的文件中的 body 元素上设置mycontent.css):

content_css : '/mycontent.css'

content_stylecan be used to tweak (or override) parts of whatever stylesheet the editor is using, regardless of whether that is the default editor CSS or one you've specified with content_css.

content_style可用于调整(或覆盖)编辑器正在使用的任何样式表的部分,无论它是默认编辑器 CSS 还是您使用content_css.

For example:

例如:

content_style: 'body { font-size: 12px; }'

More info and examples here: https://www.tiny.cloud/blog/how-to-change-the-default-font-family-size-and-color-in-tinymce.

更多信息和示例在这里:https: //www.tiny.cloud/blog/how-to-change-the-default-font-family-size-and-color-in-tinymce

回答by HRN

Simply edit

只需编辑

tinymce/themes/advanced/skins/o2k7/content.css

tinymce/themes/advanced/skins/o2k7/content.css

and change font-size at this line:

并在这一行更改字体大小:

body, td, pre {color:#000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; margin:8px;}

回答by TopQnA

Following worked for me:

以下为我工作:

CSS Path:

CSS 路径:

tinymce/js/tinymce/skins/lightgray/content.min.css

tinymce/js/tinymce/skins/lightgray/content.min.css

body{background-color:#fff;color:#000;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:14px;

body{background-color:#fff;color:#000;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:14px;

I changed from 11px to 14ox.

我从 11px 更改为 14ox。