简体   繁体   English

如何在 CKEditor 4 中设置默认字体

[英]How to set default font in CKEditor 4

I'm trying to set a default font and font-size for the CKEditor 4我正在尝试为 CKEditor 4 设置默认字体和字体大小

Found this in the CKEditor 4 documentation https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-font_style在 CKEditor 4 文档https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-font_style 中找到了这个

Like I want to change the default font to "Comic Sans MS" and the font size to "48"就像我想将默认字体更改为“Comic Sans MS”并将字体大小更改为“48”

Tried like this, but not working像这样试过,但不起作用

ckeditorConfig.font_style = {
  element:  'span',
  styles:  { 'font-family': 'Comic Sans MS' },
  overrides:  [ { element: 'font', attributes: { 'face': null } } ]
};

ckeditorConfig.fontSize_style = {
  element:  'span',
  styles:  { 'font-size': '48px' },
  overrides:  [ { element: 'font', attributes: { 'size': null } } ]
};

Found this from stack overflow, but no working examples How Can i change default font of Ckeditor?从堆栈溢出中找到了这个,但没有工作示例如何更改 Ckeditor 的默认字体?

Also setting a span on CKEditor's instanceReady is not helping Is there a way to set the default font and font-size in CKEditor?在 CKEditor 的 instanceReady 上设置跨度也没有帮助有没有办法在 CKEditor 中设置默认字体和字体大小?

----Update--- - - 更新 - -

The above CKEditor config is overriding the CKEditor's Font drop-down option and not affecting the default font.上面的 CKEditor 配置覆盖了 CK​​Editor 的字体下拉选项并且不影响默认字体。 Seems like it overrides the font selected from the drop-down to the one specified in the Config.似乎它将从下拉列表中选择的字体覆盖为配置中指定的字体。

Is there any other way to set the default font for CKEditor 4.有没有其他方法可以设置 CKEditor 4 的默认字体。

Thanks in Advance.提前致谢。

I got a solution for my use case.我为我的用例找到了解决方案。 I had a block of code where the unwanted ckeditor bookmarks were cleaned up.我有一段代码,其中清理了不需要的 ckeditor 书签。 Added a div with some inline styles specific to the font setting, to persist the font styles when thread is saved.添加了一个带有一些特定于字体设置的内联样式的 div,以在保存线程时保留字体样式。 For live UI changes, added a style to the ckeditor's parent div, to reflect the font styles while typing the content.对于实时 UI 更改,向 ckeditor 的父 div 添加样式,以在键入内容时反映字体样式。 ckeditorConfig.font_style was not useful.Used ckeditorConfig.font_defaultLabel to set the font drop down value of the ckeditor. ckeditorConfig.font_style没有用。使用ckeditorConfig.font_defaultLabel来设置ckeditorConfig.font_defaultLabel的字体下拉值。 I can't use the setData method to set styles, as it may obstruct some of the the existing code flow.我不能使用setData方法来设置样式,因为它可能会阻碍一些现有的代码流。

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

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