我认为 XHTML 文档应该以与“严格”HTML 文档完全相同的标准遵从模式显示。
但是,它们显示pre
的方式有所不同。元素:在 HTML 文档中,如果 <pre>
开始标记后跟一个 LF(或 CRLF),这将被忽略。在 XHTML 中不是这样。
示例:HTML file和一个 XHTML file具有相同的内容,但呈现方式不同。
(或者如果您认为给 HTML 文件和 XHTML 文件提供完全相同的内容(包括 DOCTYPE)是作弊,这里有两个文件遵循更经典的规则:HTML 4.01 strict 和 XHTML 1.0 strict。)
那么,这是否意味着像 this W3C page 这样的陈述?的
all line breaks and spaces are rendered exactly as they appear in the HTML. The exception is a newline immediately after the start tag <pre> and immediately before the end tag </pre>, which are discarded.
仅对 HTML 有效,对 XHTML 无效?我还没有发现任何迹象表明 XHTML 可以根据需要以不同方式显示内容。但我测试过的所有浏览器都可以。
最佳答案
开始换行的删除与 HTML 中的呈现 无关,Dave Raggett 的页面只是有点不精确而且有点过时了。删除起始换行符是 HTML 解析器的一个属性。
在in body text/html
mime 类型的 HTML5 规范树构造阶段说:
A start tag whose tag name is one of: "pre", "listing"
If the stack of open elements has a p element in button scope, then close a p element.
Insert an HTML element for the token.
If the next token is a "LF" (U+000A) character token, then ignore that token and move on to the next one. (Newlines at the start of pre blocks are ignored as an authoring convenience.)
Set the frameset-ok flag to "not ok".
XML 解析规则根本不允许 XML 解析器执行此操作,因此 XHTML 不会删除该新行。
关于html - HTML 和 XHTML 的显示差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17722951/