HTML 实体 - 替代  ?

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

HTML entitites - alternative to &nbsp?

htmlhtml-entities

提问by Siva

I am a beginner with HTML (coming from a C background) and I came across the concept of HTML entities. I have some very basic questions regarding &nbsp.

我是 HTML 的初学者(来自 C 背景),我遇到了 HTML 实体的概念。我有一些关于   的非常基本的问题。

  1. How does &nbsp entity introduce a non-breaking space within an element ?

  2. Is there any alternative to using the &nbsp entity in HTML ?

  1.   实体如何在元素中引入不间断空间?

  2. 除了在 HTML 中使用   实体之外,还有其他选择吗?

My internet searches have not given the answer I was looking for and some direction on these would be most appreciated.

我的互联网搜索没有给出我正在寻找的答案,我将不胜感激。

采纳答案by Aaron Digulla

 is an alias for  or &xa0;. This character is defined as "non-breaking space" in the HTML standard. So someone said "browser must treat this is a space but not break a line" in a standard and all people who created Web browsers adhered to this standard.

  or的别名&xa0;。该字符在 HTML 标准中被定义为“不间断空格”。所以有人在标准中说“浏览器必须把这是一个空格而不是断线”,所有创建Web浏览器的人都遵守这个标准。

If your editor supports it, you can also type this character. The browser doesn't care how it was created, only that it sees the byte 0xa0 in the input stream.

如果您的编辑器支持它,您也可以键入此字符。浏览器不关心它是如何创建的,只关心它在输入流中看到字节 0xa0。

As an alternative, you can use various CSS styles and tricks to create lengths of text that won't break (for example with the style white-space: nowrap(see here) or by using padding / margins.

作为替代方案,您可以使用各种 CSS 样式和技巧来创建不会中断的文本长度(例如使用样式white-space: nowrap(参见此处)或使用填充/边距)。

Related:

有关的:

回答by isherwood

  1. &nbspis simply a reference to a [particular] space character [see comments]. It renders in the font specified for its location.

  2. Sure. The space character. Or you can split the element and apply padding or margin via CSS.

  1. &nbsp只是对[特定]空格字符的引用[见评论]。它以为其位置指定的字体呈现。

  2. 当然。空格符。或者您可以拆分元素并通过 CSS 应用填充或边距。