Html 何时使用  

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16951133/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:08:56  来源:igfitidea点击:

When to use &nbsp

html

提问by jlars62

I have seen &nbspin html and can't quite tell what it does other than create some whitespace. I am wondering what exactly it does and when it should be used?

&nbsp在 html 中看到过,除了创建一些空白之外,无法完全说明它的作用。我想知道它到底是做什么的,什么时候应该使用它?

回答by Quentin

 (it should have a semi-colon on the end) is an entity for a non-breaking space.

 (它应该在末尾有一个分号)是一个不间断空格的实体。

Use it between two words that should not have a line break inserted between them by word wrapping.

在两个不应通过换行在它们之间插入换行符的单词之间使用它。

There is a good explanation about when this is appropriate grammaron the English StackExchange.

关于何时在英语 StackExchange 上使用合适的语法一个很好的解释



It is sometimes abused to create horizontal space between content in web pages (since it will not collapse like multiple regular spaces). Padding and margins should usually be used instead of this hack.

有时会滥用在网页内容之间创建水平空间(因为它不会像多个常规空间一样折叠)。通常应该使用填充和边距来代替这个 hack。

回答by Jiaaro

One reason for  is to insert multiple spaces in a document.

原因之一 是在文档中插入多个空格。

In HTML, multiple whitespace characters are collapsed into one space. This includes tabs and newlines.

在 HTML 中,多个空白字符合并为一个空格。这包括制表符和换行符。

IF you wanted to display the following:

如果您想显示以下内容:

three   spaces.

You could insert 3  entities instead of using spaces like so:

您可以插入 3 个 实体而不是像这样使用空格:

three   spaces.

Edit: It's worth mentioning that  is more of a historical artifact than anything else. Just about every use for it that is mentioned in the answers to this question has a better alternative means to accomplish that goal. However,  is still with us, and these are some of the things people have used it for.

编辑:值得一提的是, 它更像是一件历史文物。这个问题的答案中提到的几乎所有用途都有更好的替代方法来实现该目标。然而, 它仍然伴随着我们,这些是人们使用它的一些东西。

See also: http://www.sightspecific.com/~mosh/www_faq/nbsp.html

另见:http: //www.sightspecific.com/~mosh/www_faq/nbsp.html

回答by Lisa Beck

I don't know if this answers your question or not and certainly this answer is not of the caliber already provided by others, but the beauty of a discussion thread or Q&A site is the diversity of experience that might be found in it. So, on that note, I'll share with you what I've used nbsp;for. (To be perfectly honest, 24 hours ago, nbsp;was something I had never even heard of.)

我不知道这是否回答了您的问题,当然这个答案不是其他人已经提供的水准,但讨论主题或问答网站的美妙之处在于其中可能会发现的经验的多样性。因此,在此说明上,我将与您分享我的用途nbsp;。(说实话,24 小时前,nbsp;我什至从未听说过。)

Here's how I used nbsp;. I was posting something using markdown language and I had a very simple two-item bulleted list. For the life of me I could not get the spacing before this list and after to look symmetrical. So, I did a web search and somehow ended up taking a look at this thread.

这是我如何使用nbsp;. 我正在使用降价语言发布一些内容,并且我有一个非常简单的两项项目符号列表。对于我的生活,我无法在此列表之前和之后获得看起来对称的间距。因此,我进行了网络搜索,并以某种方式最终查看了此线程。

Before using nbsp;the paragraph that followed bullet point #2 collapsed the spacing between the bulleted point and the text, making it look as if the paragraph had something to do with bullet #2, specifically (which was not the case).I tried a lot of different things that I can't even remember now, but the one thing that ultimately worked was insertion of nbsp;.

在使用nbsp;项目符号 #2 后面的段落之前,折叠了项目符号与文本之间的间距,使其看起来好像该段落与项目符号 #2 有关系,特别是(事实并非如此)。我尝试了很多不同的东西,我现在都记不清了,但最终奏效的一件事是插入nbsp;.

Since then, I've been seeing all sorts of posts that indicate some controversy over its use, but for non-coderswho need to wrangle out of an unsightly/misleading formatting issue, nbsp;is a very quick and useful fix.

从那时起,我一直看到各种帖子表明对其使用存在一些争议,但对于需要解决难看/误导性格式问题的非编码人员来说,这nbsp;是一个非常快速且有用的解决方案。