Inline contenteditable tags fail to align correctly in IE

你离开我真会死。 提交于 2019-12-22 06:46:46

问题


I have a situation where I have inline contenteditable span tags together with other non-contenteditable tags which work fine in all browsers except for IE. In IE the tags fail to act as inline and start forcibly aligning themselves as block (sort of). I need something to make them act as inline. It seems that IE is forcing some weird behaviour when the tag is contentedtiable.

<div class="container">
<span class="text" contenteditable="true">Lorem ipsum dolor </span>
<span class="tag">Tag</span>
<span class="text" contenteditable="true"> sed dignissim maximus mattis </span>
<span class="tag">Tag</span>
<span class="text" contenteditable="true"> vel ex ut nisi elementum tincidunt libero</span>

Here is the fiddle with an example: http://jsfiddle.net/glennmicallef/m7tkgo2u/

Open the fiddle in both IE and Chrome (for example) to see the difference.


回答1:


In my case, I used the :before and :after pseudo-elements to achieve this.

[contenteditable=true]:before {
  content: attr(before-content);
  margin-right: 2px;
}
<div class="container">
  <span class="text" contenteditable="true">Lorem ipsum dolor </span>
  <span before-content="Tag" contenteditable="true"> sed dignissim maximus mattis </span>
  <span before-content="Tag" contenteditable="true"> vel ex ut nisi elementum tincidunt libero</span>
</div>

This keeps the pseudo-element part non-editable and the rest editable.

The UX is only good on IE though...



来源:https://stackoverflow.com/questions/25662990/inline-contenteditable-tags-fail-to-align-correctly-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!