How to indent the first line of a paragraph in CKEditor

后端 未结 2 1879
情话喂你
情话喂你 2021-01-23 06:17

I\'m using CKEditor and I want to indent just the first line of the paragraph. What I\'ve done before is click \"Source\" and edit the

style to include

2条回答
  •  春和景丽
    2021-01-23 06:33

    Depending on which version of CKE you use, your changes most likely disappear because ether the style attribute or the text-indent style is not allowed in the content. This is due to the Allowed Content Filter feature of CKEditor, read more here: http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter

    Like Ervald said in the comments, you can also use CSS to do this without adding the code manually - however, your targeting options are limited. Either you have to target all paragraphs or add an id or class property to your paragraph(s) and target that. Or if you use a selector like :first-child you are restricted to always having the first element indented only (which might be what you want, I don't know :D).

    To use CSS like that, you have to add the relevant code to contents.css, which is the CSS file used in the Editor contents and also you have to include it wherever you output the Editor contents.


    In my opinion the best solution would indeed be making a plugin that places an icon on the toolbar and that button, when clicked, would add or remove a class like "indentMePlease" to the currently active paragraph. Developing said plugin is quite simple and well documented, see the excellent example at http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_1 - if you need more info or have questions about that, ask in the comments :)

    If you do do that, you again need to add the "indentMePlease" style implementation in contents.css and the output page.

提交回复
热议问题