我正在使用 ckeditor
我想问一下这个插件如何设置font-family和font-size, 我尝试过使用
CKEDITOR.config.font_defaultLabel = 'Arial';
CKEDITOR.config.fontSize_defaultLabel = '12px';
但是这些命令只是改变前端(字体名称和大小)
出路在哪里?
最佳答案
最面向 future 的方法(1) 是覆盖您想要在单独文件中更改的 CKEditor 内容的默认 CSS 样式,并将其添加到您的 editor configuration 中。通过config.contentsCss
选项。
请参阅 CKEditor SDK 中此场景的工作示例:http://sdk.ckeditor.com/samples/classic.html
向下滚动到“具有自定义样式的经典编辑器”示例;您可以在示例页面的“获取示例源代码”部分下载该解决方案的确切源代码。在本例中,自定义字体和其他样式在单独的 classic.css
文件中定义,然后将其提供给编辑器实例配置:
<script>
CKEDITOR.replace( 'myeditor', {
/* Default CKEditor styles are included as well to avoid copying default styles. */
contentsCss: [ 'contents.css', 'classic.css' ]
} );
</script>
请记住,它仅对 classic editor 有效。如in inline editor content styles are the same as the page styles ,因此所有内容样式都直接来自页面样式表。
(1) 此方法比修改默认 contents.css
文件更好,因为当您 upgrade CKEditor 时,您不会面临覆盖更改的风险。 .
关于javascript - 在 CKEditor 中设置字体大小和字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27155789/