Html 处理非中断空间:<p> </p> vs. <p> </p>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12279611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Handling of non breaking space: <p> </p> vs. <p> </p>
提问by grabner
is a non breaking space, which represents an empty space where no line break occurs.
是一个非换行空格,表示不发生换行的空白区域。
If I use
如果我使用
<p> </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?
我在两个段落之间只有一条新线(没有中断)。为什么?
回答by BoltClock
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.
在 HTML 中,只包含普通空白字符的元素被认为是空的。仅包含普通空格字符的段落将具有零高度。不间断空格是一种特殊的空白字符,不被认为是无关紧要的,因此它可以用作非空段落的内容。
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.
即使您考虑段落的 CSS 边距,由于“空”段落的高度为零,其垂直边距也会折叠。这导致它没有高度和边距,使它看起来好像根本不存在。
回答by Roshdy
How about a workaround?
In my case I took the value of the textarea in a jQuery variable, and changed all "<p> "
to <p class="clear">
and clear class to have certain height and margin, as the following example:
如何解决?在我的例子中,我在 jQuery 变量中获取了 textarea 的值,并将 all 更改"<p> "
为<p class="clear">
和 clear 类以具有一定的高度和边距,如下例所示:
jQuery
jQuery
tinyMCE.triggerSave();
var val = $('textarea').val();
val = val.replace(/<p> /g, '<p class="clear">');
the val is then saved to the database with the new val.
然后将 val 与新的 val 一起保存到数据库中。
CSS
CSS
p.clear{height: 2px; margin-bottom: 3px;}
You can adjust the height & margin as you wish. And since 'p' is a display: blockelement. it should give you the expected output.
您可以根据需要调整高度和边距。因为 'p' 是一个display: 块元素。它应该给你预期的输出。
Hope that helps!
希望有帮助!
回答by Roshdy
If I understand your issue this should work
如果我理解你的问题,这应该有效
&emsp—the em space; this should be a very wide space, typically as much as four real spaces. &ensp—the en space; this should be a somewhat wide space, roughly two regular spaces. &thinsp—this will be a narrow space, even more narrow than a regular space.
&emsp——em 空间;这应该是一个非常宽的空间,通常多达四个真实空间。&ensp——空间;这应该是一个有点宽的空间,大约是两个常规空间。&thinsp——这将是一个狭窄的空间,甚至比普通空间更窄。
Sources: http://hea-www.harvard.edu/~fine/Tech/html-sentences.html
资料来源:http: //hea-www.harvard.edu/~fine/Tech/html-sentences.html