无法获取contentEditable中的空段落

问题描述 投票:2回答:3

我有一个contentEditable文章,带有“EmbeddedSection”div(递归),它们上面和下面都有一个段落。在chrome中,如果段落为空,则实际上无法实现。在IE中你可以,但大小都是错的。

http://jsfiddle.net/hE8zS/1/

<article contenteditable="true">
   <p><span class="numbering">Title</span><span class="TextChunk"></span></p>
   <div class="EmbeddedSection">
       <p><span class="numbering">1</span><span class="TextChunk">Section Title</span></p>   
       <div class="EmbeddedSection">
           <p><span class="numbering">1.1</span><span class="TextChunk">Embedded title</span></p>
           <p><span class="TextChunk">Th</span><span class="TextChunk">e </span><span class="TextChunk">.</span></p>
       </div>
       <p><span class="TextChunk"></span></p> <!--Can't get to this element-->
       <div class="EmbeddedSection">
           <p class="Paragraph"><span class="numbering">1.2</span><span class="TextChunk">Another title</span></p>
           <p class="Paragraph"><span class="TextChunk">Blah blah blah</span></p>
       </div>
       <p><span class="TextChunk">Can get here, but not the one above 1.2 in chrome (ie gets there).</span></p>
       <div class="EmbeddedSection">
           <p class="Paragraph"><span class="numbering">1.3</span><span class="TextChunk">Another title</span></p>
           <p class="Paragraph"><span class="TextChunk">Blah blah blah</span></p>
        </div>
        <p><span class="TextChunk"></span></p> <!--Can't get to this element-->
    </div>
</article>

有没有人知道我是否能够设置空段落的样式,或者以某种方式将它们标记为可以使它们可以访问的东西?

(注意:即使在用户编辑并删除了该空白字符之后,即使只有一个空格字符也能正常工作。)

javascript css html5 contenteditable
3个回答
7
投票

你可以加

:empty {
    display: block;
    height: 1em;
}

它似乎工作:http://jsfiddle.net/hE8zS/3/

此页面包含有关浏览器兼容性的信息:https://developer.mozilla.org/en-US/docs/Web/CSS/:empty


0
投票

我实际上已经开始使用:空,因为它没有选择正确并且不能满足于满足。

我实际上最终在任何空的段落中放入一个零宽度的空白(以及一些相关的javascript以在keypress上跳过它),这意味着它正确地调整大小,并且与contenteditables很好地配合。在这里查看我的错误报告http://code.google.com/p/chromium/issues/detail?id=292334


0
投票

简单的占位符:contenteditable:

[contenteditable]:empty::before {
    content: 'Your Placeholder Text';
    color: rgba(0,0,0,0.2);
}
© www.soinside.com 2019 - 2024. All rights reserved.