非中断空间的处理:< p& nbsp;</p>与< p> </p> [英] Handling of non breaking space: <p> </p> vs. <p> </p>

查看:229
本文介绍了非中断空间的处理:< p& nbsp;</p>与< p> </p>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 是一个不间断空格,表示没有换行的空白空间.

  is a non breaking space, which represents an empty space where no line break occurs.

如果我使用

<p>&nbsp;</p>

我在两个段落之间有一个空格(较大的中断).如果我使用

I have a space between two passages (bigger break). If I use

<p> </p>

我在两个段落之间只有一个换行符(不间断).为什么?

I only have a new line between the two passage (no break). Why?

推荐答案

在HTML中,仅包含普通空格字符的元素被认为是空的.仅包含普通空格字符的段落的高度将为零.不间断空格是一种特殊的空格字符,它不被认为是无关紧要的,因此可以用作非空段落的内容.

In HTML, elements containing nothing but normal whitespace characters are considered empty. A paragraph that contains just a normal space character will have zero height. A non-breaking space is a special kind of whitespace character that isn't considered to be insignificant, so it can be used as content for a non-empty paragraph.

即使您考虑在段落上使用CSS边距,由于空"段落的高度为零,其垂直边距也会

Even if you consider CSS margins on paragraphs, since an "empty" paragraph has zero height, its vertical margins will collapse. This causes it to have no height and no margins, making it appear as if it were never there at all.

这篇关于非中断空间的处理:&lt; p&amp; nbsp;&lt;/p&gt;与&lt; p&gt; &lt;/p&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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