You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3 CKEditor:如何减少两行之间的间距

Fixing Extra Line Spacing in CKEditor When Pressing Enter

I’ve run into this exact issue before—super frustrating when hitting Enter adds way more space than you want! Here are a few straightforward ways to fix it:

Quick Fix: Use Shift+Enter Instead of Enter

By default, CKEditor treats a single Enter press as creating a new paragraph (<p> tag), which comes with built-in top/bottom margins. If you just want a line break without the extra spacing, press Shift+Enter instead. This inserts a <br> tag, which gives you a clean single line break.

Change Enter’s Default Behavior (CKEditor 4)

If you want Enter to always create a line break (instead of a paragraph), adjust the editor’s configuration by adding this code to your CKEditor setup:

CKEDITOR.editorConfig = function( config ) {
    // Make Enter insert a line break (<br>)
    config.enterMode = CKEDITOR.ENTER_BR;
    // Optional: Set Shift+Enter to create a new paragraph
    config.shiftEnterMode = CKEDITOR.ENTER_P;
};

Reduce Paragraph Spacing with Custom CSS

If you still want to use paragraphs (for proper semantic structure) but need less spacing between them, customize the editor’s content CSS with this style rule:

p {
    margin-top: 0;
    margin-bottom: 0.5em; /* Tweak this value to get your desired spacing */
}

To apply this in CKEditor 4:

  • Add the CSS to your site’s existing stylesheet and link it via config.contentsCss in the editor config, or
  • Use the editor’s built-in stylesheet editor (if available in your setup).

For CKEditor 5 Users

In CKEditor 5, adjust paragraph spacing using the editor’s configuration or custom styles. For example, modify default paragraph margins with this code:

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        styles: {
            definitions: [
                {
                    name: 'Paragraph',
                    element: 'p',
                    styles: {
                        'margin-bottom': '0.5em',
                        'margin-top': '0'
                    }
                }
            ]
        }
    } )
    .catch( error => {
        console.error( error );
    } );

Alternatively, use the CKEditor 5 Style Guide plugin to visually adjust spacing if you have access to it.

Hope one of these solutions works for you!

内容的提问来源于stack exchange,提问作者moho123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 10:47:29