如何在CKEditor中缩进段落的第一行 [英] How to indent the first line of a paragraph in CKEditor
问题描述
我正在使用 CKEditor ,并且只想缩进该段的第一行。我之前所做的是单击源代码并编辑< p>
样式以包括 text-indent:12.7mm;
,但是当我再次单击源返回到普通编辑器时,我的更改消失了,我也不知道为什么。
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 <p>
style to include text-indent:12.7mm;
, but when I click "Source" again to go back to the normal editor, my changes are gone and I have no idea why.
我的偏好设置是是创建自定义工具栏按钮,但我不确定如何执行操作或在何处进行编辑,因此单击自定义按钮将使用< p>
My preference would be to create a custom toolbar button, but I'm not sure how to do so or where to edit so that clicking a custom button would edit the <p>
with the style attribute I want it to have.
推荐答案
根据您使用的CKE版本,您的更改很可能会消失,因为以太内容中不允许使用 style
属性或 text-indent
样式。这是由于CKEditor的允许的内容筛选器功能,请在此处阅读更多信息: http:// docs。 ckeditor.com/#!/guide/dev_advanced_content_filter
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
就像Ervald在评论中所说,您也可以使用CSS来做到这一点,而无需手动添加代码-但是,您的定位选项受到限制。您必须将所有段落作为目标,或者将id或class属性添加到段落中并以此为目标。或者,如果您使用:first-child
之类的选择器,则只能始终缩进第一个元素(这可能就是您想要的,我不知道:D )。
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).
要使用CSS,您必须将相关代码添加到 contents.css
中,编辑器内容中使用的CSS文件,而且无论输出编辑器内容的位置如何,都必须包含它。
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.
在我的最好的解决方案实际上是制作一个在工具栏上放置一个图标的插件,并且单击该按钮后,将在当前活动的段落中添加或删除 indentMePlease之类。开发上述插件非常简单且有据可查,请参见 http://docs.ckeditor中的出色示例.com /#!/ guide / plugin_sdk_sample_1 -如果您需要更多信息或对此有疑问,请在评论中提问:)
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 :)
如果这样做那,您再次需要在contents.css和输出页面中添加 indentMePlease样式的实现。
If you do do that, you again need to add the "indentMePlease" style implementation in contents.css and the output page.
这篇关于如何在CKEditor中缩进段落的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!