【发布时间】:2019-07-02 16:59:20
【问题描述】:
我想在 contenteditable 区域中编辑文本之前和之后添加空格,例如前后一个空格,那么我该如何使用 CSS 来做到这一点。这是我的脚本:jsfiddle
[contenteditable="true"] {
background-color: DodgerBlue;
}
[contenteditable="true"]:focus {
background-color: white;
color : black;
}
span.a {
border: 1px solid white;
}
span.a:empty {
padding-right:10px;
}
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
<span class="a" contenteditable="true">
when an unknown printer
</span> took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
【问题讨论】:
-
双击,选中一个词,后面加个空格,还不够吗?
-
@G-Cyr 我希望整个过程是自动的,以便用户在编辑文本时;编辑后的文字前后各有一个空格
-
[contenteditable="true"]::before,[contenteditable="true"]::after {content:' ';}够了吗? jsfiddle.net/mfkh39yt -
@G-Cyr 我非常感谢您的解决方案确实有效。
标签: html css contenteditable