首页 > 解决方案 > 带cdn的行距

问题描述

如果我使用 CDN,如何设置 ckeditor 的单行间距?

我看到了几个插件来解决这个问题,但我只想使用 cdn 并在按下回车键时将其保留为单个空格。

提前致谢

标签: ckeditorcdn

解决方案


ckeditor 不会添加额外的行距,它只是为每个编写的段落添加 ap 标签,当您按下 ENTER 时,会为您编写的下一个段落创建一个新的 p 段落标签。

您看到的可能是margin-bottom: 25px;默认应用于段落的 CSS 规则。要减少此边距,只需使用如下规则创建一个 CSS 文件:

body.article-editor p {
    margin-bottom: 10px;
}

即使您只是导入 CDN,我假设您正在代码中某个<script>标记内的某处初始化 ckeditor。在这段 JavaScript 代码中,设置 CKEDITOR 配置 contentsCss 如下:

CKEDITOR.config.contentsCss = '/css/mysitestyles.css';

有关其工作原理的更多信息,请查看有关 contentsCss 配置属性的文档: https ://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-contentsCss


反馈后编辑:

感谢您分享您的代码。我已经更正了您的 HTML,因为您有几个小的 HTML 错误:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>CKEditor</title>
    <script src="https://cdn.ckeditor.com/4.12.1/standard/ckeditor.js"></script>
    </head>
<body>
    <textarea name="editor1"></textarea>
    <script>
        CKEDITOR.config.contentsCss = 'mystyles.css';
        CKEDITOR.replace( 'editor1' );
     </script>
    </body>
</html>

此外,由于您在文本编辑模式而不是文章编辑模式下使用 Ckeditor,请改用此 CSS:

.cke_editable p {
    margin-top: 0px;
    margin-bottom: 0px;
}

这适用于 Firefox 最新版本。


推荐阅读