空的段落标签 - 我应该允许在HTML编辑器中吗? [英] Empty paragraph tags - should I allow in HTML editor or not?

查看:139
本文介绍了空的段落标签 - 我应该允许在HTML编辑器中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CKEditor 4,它似乎具有使用< p>< / p> 的默认设置来指示空行。到目前为止,我一直在HTML中看到由< p>& nbsp;< / p> - 表示的空行。不是一个空标签。



因此,CKEditor的默认输出代表一个空行,例如:

 < p>段落在空行之前< / p> 
< p>< / p>
< p>段落后的空白行< / p>

问题是,对于一个更改,IE7,8,9似乎将此正确渲染为一个空行,而Firefox和Chrome却没有 - 它们似乎忽略了空的< p> < div> 标签,就布局而言。

所以,现在我必须告诉CKEditor包含& nbsp; 在空白行(不是由于某种原因它的默认设置),并且在后端,替换出现可能滑过的任何空的< p> 标签。

我的问题是,在HTML中表示空白行的黄金标准是什么?古老的< p>& nbsp;< / p> 或其他什么?

另外,考虑到CKEditor的默认设置是空白行的空白< p> 标签,Chrome和Firefox是否错误地忽略了它们?或者IE浏览器错误地将它们渲染为空行,而CKEditor的默认设置应该是使用< p>& nbsp;< / p>

解决方案

根据 p 元素< p>< / p> HTML 4.01 >是有效的,但不应该被使用,浏览器应该忽略它。浏览器行为不一致,通常不遵守规范。例如,您可以使用< hr>< hr>< p>< / p>< hr>< / code> code> p 元素的高度为零,它具有顶部和底部边距,因此它会影响渲染,即不会被忽略。 - HTML5 CR似乎对这个问题保持沉默,即它没有针对具有空白内容的 p 元素说明任何具体内容。 更新: HTML5的一般性声明中有关措辞的元素内容作为内容模式(例如 p ):这样一个元素应该包含至少应该有一个不是元素间空白的后代文本节点,或者至少一个嵌入内容的后代元素节点。这意味着不应该使用< p>< / p> ;但这是一个建议,而不是一致性要求(应该,而不是应该)。

< p& amp; amp (不间断空格字符的渲染尚未定义),但浏览器通常将无间断​​空间视为另一个图形字符,这恰好是用空字形呈现的。所以实际上它会生成一个线框,其高度由计算值 line-height



默认情况下, p 元素之间存在空白,对应于一个空行。因此,任何需要在 p 元素之间出现空行的需求似乎是由重写默认样式造成的,例如 p {margin:0} 在CSS中。为了覆盖它,应该使用额外的CSS而不是人为的 p 元素。也就是说,一些 p 元素应该有一个合适的非零底部或顶部边距。



HTML 4.01定义了<参考Ascii空间,Ascii标签,Ascii换页符,空格字符 ,以及零宽度空间(例如 not 为无间断空间),定义它们的渲染,并添加:此规范不指示其他空间字符的行为,渲染或其他方式而不是那些在这里明确指定为空格字符的人。出于这个原因,作者应该使用适当的元素和样式来实现涉及空格的视觉格式效果,而不是空格字符。


I'm using CKEditor 4, which seems to have a default setting of using <p></p> to indicate a blank line. Up to now, I've always seen blank lines in HTML represented by <p>&nbsp;</p> - ie. not an empty tag.

So CKEditor's default output representing a blank line is, eg:

<p>paragraph before blank line</p>
<p></p>
<p>paragraph after blank line</p>

The problem is, for a change, IE7,8,9 seems to render this "correctly" as a blank line, whereas Firefox and Chrome do not - they seem to ignore empty <p> and <div> tags, in terms of layout.

So, at the moment, I have to tell CKEditor to include &nbsp; in blank lines (not its default setting for some reason) and, at the back-end, replace any occurrences of empty <p> tags that may slip through.

My question is, what is the gold standard for representing blank lines in HTML? The good-old <p>&nbsp;</p>, or something else?

Also, given that CKEditor's default setting is an empty <p> tag for blank lines, are Chrome and Firefox wrong to ignore them? Or is IE wrong to render them as blank lines, and CKEditor's default should really be to use <p>&nbsp;</p>?

解决方案

As per HTML 4.01 on the p element, <p></p> is valid but should not be used, and browsers should ignore it. Browser behavior is inconsistent and generally does not obey the spec. You test this with <hr><hr><p></p><hr> for example – on Chrome, it shows that although the p element has zero height, it has top and bottom margins, so it affects rendering, i.e. is not ignored. – The HTML5 CR seems to be silent about this issue, i.e. it does not say anything specific about a p element with empty content. Update: HTML5 has a general statement about elements with phrasing content as the content mode (such as p): such an element should contain "should have either at least one descendant Text node that is not inter-element whitespace, or at least one descendant element node that is embedded content". This means that <p></p> should not be used; but this is a recommendation, not a conformance requirement ("should", not "shall").

The effect of <p>&nbsp;</p> is undefined by the spec (the rendering of the no-break space character has not been defined), but browsers generally treat no-break space as yet another graphic character, which just happens to be rendered with an empty glyph. So in practice it generates a line box, with a height determined by the computed value of line-height.

By default, there are margins between p elements, corresponding to one empty line. So any need for a blank line between p elements seems to have been caused by overriding the default styling, by something like p { margin: 0 } in CSS. In order to override that, additional CSS rather than an artificial p element should be used. That is, some of p elements should have a suitable nonzero bottom or top margin.

The HTML 4.01 defines "white space characters" as referring to Ascii space, Ascii tab, Ascii form feed, and zero-width space (thus, not to no-break space for example), defines their rendering, and adds: "This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters."

这篇关于空的段落标签 - 我应该允许在HTML编辑器中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆