HTML空格:空格前后

前端之家收集整理的这篇文章主要介绍了HTML空格:空格前后前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在努力更好地了解 HTML空白处理模型.现在我正在比较两个HTML片段:
<div>a <br>z</div>

<div>a<br> z</div>

第一个代码片段被重绘时,会产生两行:“a”和“z”(所以第一行有一个尾随空格).

第二个片段产生两行:“a”和“z”.第二行没有领先空间.

我的问题是:为什么?我正在使用这个http://www.w3.org/TR/CSS2/text.html#white-space-model作为参考.它指出

  1. If a space (U+0020) at the beginning of a line has ‘white-space’ set to ‘normal’,‘nowrap’,or ‘pre-line’,it is removed.
  2. All tabs (U+0009) are rendered as a horizontal shift that lines up the start edge of the next glyph with the next tab stop. Tab stops occur at points that are multiples of 8 times the width of a space (U+0020) rendered in the block’s font from the block’s starting content edge.
  3. If a space (U+0020) at the end of a line has ‘white-space’ set to ‘normal’,it is also removed.
  4. If spaces (U+0020) or tabs (U+0009) at the end of a line have ‘white-space’ set to ‘pre-wrap’,UAs may visually collapse them.

对此的幼稚阅读将表明,由于要删除行的开头或结尾的空格(当“空白”为“正常”)时,我的第一个片段应该不会导致尾随空格.但事实并非如此.

发生什么了?

我目前的理论是< br>被秘密地算作一个“字符”,在第一个代码片段中,它阻止了尾随空格处于其行的“结束”.但我真的不知道.

编辑:要清楚,我知道如何使用& nbsp;随意创建空格.我的问题是关于什么规则(关于某些规范)会引起上述行为.

解决方法

好问题!我已经确认了Chrome和Firefox中的行为,并确认它与< br&gt无关,因为它也是由白色空间中的普通线路断开引发的:前线条件:
<div style="white-space:pre-line">a 
z</div>

我有sent an email to the list要求澄清这个问题,并询问我们是否应该改变规范来匹配实现,或浏览器上的文件错误以匹配规范.

原文链接:https://www.f2er.com/html/230646.html

猜你在找的HTML相关文章