Why does HTML require that multiple spaces show up as a single space in the browser?(为什么 HTML 要求多个空格在浏览器中显示为单个空格?)
问题描述
我早就认识到 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 要求多个空格在浏览器中显示为单个空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 HTML 要求多个空格在浏览器中显示为单个


基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01