我无法弄清如何修改CKeditor iframe的body
CSS样式。基于网络上的各种潜在解决方案,我尝试了一堆选项,但我对CKeditor的API不是很熟悉,这使得事情变得相当困难。这是(具体地说)CKeditor 4.4.3。
您可以在以下JSFiddle上看到各种尝试(已注释):
CKEDITOR.stylesSet.add( 'style_updates', [
// ATTEMPT 1
// Block-level styles...this is for the dropdown menu (not shown in current config)
{ name: 'Body Margin Fix', element: 'body', styles: { margin: '10px' } }
]);
editor = $('textarea').ckeditor( function(editor){
// ATTEMPT 2
//callback `this` refers to CKEDITOR.editor
this.ckeditorGet().addCss('body { margin:10px; }')
}, {
// ATTEMTP 3
addCss: 'body { margin:10px; }',
stylesSet: 'styles_updates',
uiColor: '#FFFFFF',
scayt_autoStartup: true,
autoGrow_onStartup: true,
enterMode: CKEDITOR.ENTER_BR,
removePlugins: 'elementspath, resize',
toolbar: [
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline' ] },
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'PasteFromWord', 'Undo', 'Redo' ] },
{ name: 'links', items: [ 'Link', 'Unlink' ] },
{ name: 'editing', groups: [ 'spellchecker' ], items: [ 'Scayt' ] },
{ name: 'tools', items: [ 'Maximize' ] }
]
// ATTEMPT 4
}).ckeditorGet().addCss('body { margin:10px; }');
CKEDITOR.addCss()
,但是您需要在创建编辑器实例之前执行此操作。 - Reinmarconfig.js
和contents.css
文件了,但这些文件对于真正的初学者来说简化了设置过程。不过,您可以简单地使用config.contentsCss
和config.customConfig
,并将这些文件放在CKEditor目录之外。那么升级就会变得容易。我们例如建议在CKEditor CDN页面上采用这种方式。 - Reinmar