我早就认识到 HTML 文件中的任何一组空格都只会显示为一个空格.例如,这个:
I have long recognized that any set of whitespace in an HTML file will only be displayed as a single space. For instance, this:
<p>Hello. Hello. Hello. Hello. Hello.</p>
显示为:
你好.你好.你好.你好.你好.
Hello. Hello. Hello. Hello. Hello.
这很好,好像您需要多个预先格式化的文本空格,您可以使用 <pre>标签.但原因是什么?更准确地说,为什么在 HTML 规范中会出现这种情况?
This is perfectly fine, as if you need multiple spaces of pre-formatted text you can just use the <pre> tag. But what is the reason? More precisely, why is this in the specification for HTML?
HTML 中的空格是压缩的,因为 HTML 的格式化方式和呈现方式之间存在区别.考虑这样一个页面:
Spaces are compacted in HTML because there's a distinction between how HTML is formatted and how it should be rendered. Consider a page like this:
<html>
<body>
<a href="mylink">A link</a>
</body>
</html>
例如,如果 HTML 使用空格缩进,则链接前面会带有多个空格.
If the HTML was indented using spaces for example, the link would be preceded by several spaces.
这篇关于为什么 HTML 要求多个空格在浏览器中显示为单个空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
由于 MIME 类型而未加载样式表Stylesheet not loaded because of MIME-type(由于 MIME 类型而未加载样式表)
从 contentEditable div 中删除格式Remove formatting from a contentEditable div(从 contentEditable div 中删除格式)
格式化此 JavaScript 行Formatting this JavaScript Line(格式化此 JavaScript 行)
JavaScript 格式:大括号必须与 if/function/etc 关键字在JavaScript formatting: must braces be on the same line as the if/function/etc keyword?(JavaScript 格式:大括号必须与 if/function/etc 关键字在同
<tag></tag> 有什么区别?和&aWhat#39;s the difference between lt;taggt;lt;/taggt; and lt;tag /gt; in HTML?(lt;taggt;lt;/taggt; 有什么区别?和lt;标签/gt;在 HTML 中?)
jquery按长度限制文本jquery limit text by length(jquery按长度限制文本)