如何在 HTML 中创建小空间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2720770/
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
How to create small SPACES in HTML?
提问by user89021
There is em dash and en dash. Is there an "en" equivalent to ? Is there an enequivalent to pure Ascii 32?
有 em dash 和 en dash。是否有相当于 的“en” ? 是否有等同于纯Ascii 32的en?
I want a better way to write this:
我想要一个更好的方法来写这个:
123<span class="spanen"> </span>456<span class="spanen"> </span>789
or this:
或这个:
123<span class="spanen"> </span>456<span class="spanen"> </span>789
采纳答案by ANeves
Don't use hacks that make no sense. If you wish to separate some words, I suggest you use the CSS property word-spacing:
不要使用毫无意义的黑客。如果你想分隔一些单词,我建议你使用 CSS 属性word-spacing:
.strangeNumbers {
word-spacing: 0.5em;
}
<span class="strangeNumbers">123 456</span>
回答by knittl
 
(thin space) should do
 
(薄空间)应该做
Note that
has not the same with as an —
(—); to separate numbers you should use a narrow no-break space (U+202F).
注意
有不一样的与作为—
(—); 要分隔数字,您应该使用狭窄的不间断空格 (U+202F)。
As others have mentioned, you are better off using the CSS property word-spacing
to define the width of your spaces. it's probably a good idea to combine it with white-space:nowrap;
正如其他人所提到的,最好使用 CSS 属性word-spacing
来定义空间的宽度。将它与white-space:nowrap;
回答by Gumbo
The Unicode character U+2002 EN SPACE( 
,  
or as entity reference  
) is a space with en width.
Unicode 字符 U+2002 EN SPACE( 
, 
或作为实体引用 
)是一个具有 en 宽度的空格。
回答by fyngyrz
 
... and various other non-standard space characters are not properly implemented in some fixed fonts.
...以及其他各种非标准空格字符在某些固定字体中没有正确实现。
This will will foul up your rendering on the web browser end in an uncontrollable manner, and you can't fix it by being specific about the font, because you can't control what actual font is being used by the web browser — even if you specify the font-name or font-family, that doesn't mean the font they have is the same as the font youhave.
这将以无法控制的方式破坏您在 Web 浏览器端的渲染,并且您无法通过特定字体来修复它,因为您无法控制 Web 浏览器使用的实际字体 - 即使您指定字体名称或字体系列,这并不意味着它们拥有的字体与您拥有的字体相同。
But you can build a 100%-compatible space of any size you want, though, and it's very easy. The emvalue is the currentfont-size
. It's the height, but whatever the width of the font is, it's always a constant relative to the height in a fixed-width font. So you can take advantage of that.
但是,您可以构建任意大小的 100% 兼容空间,而且非常容易。该EM值是当前font-size
。它是高度,但无论字体的宽度是多少,它始终是相对于固定宽度字体高度的常数。所以你可以利用这一点。
Here's how to make a 1/2 width, non-breaking spacewithin the context of a fixed-width font that works with everything. I show it implemented in a span's style=""
option, but of course you can make a CSS class instead to make its use less clumsy:
以下是如何在适用于所有内容的固定宽度字体的上下文中创建1/2 宽度的不间断空间。我展示了它是在 span选项中实现的,但是当然你可以创建一个 CSS 类来使它的使用不那么笨拙:style=""
<span style="font-size: .5em;"> </span>
Here's how to make a 1/4 width, non-breakingspace:
以下是如何制作1/4 宽度的不间断空间:
<span style="font-size: .25em;"> </span>
...and so on.
...等等。
This always works with space sizes smaller than the current full-width space because the character is shorter than the other characters on the line, so they control the line spacing, not the shorter character.
这总是适用于小于当前全角空间的空间大小,因为字符比行上的其他字符短,因此它们控制行间距,而不是较短的字符。
If you want a space that is widerthan one space, use a combination of full spaces and shorter spaces. While you willget a wider space if you use something like 1.5em
, you will also get a taller space, and so that will affect the line spacing.
如果您想要一个比一个空间更宽的空间,请使用完整空间和较短空间的组合。如果你使用类似的东西你会得到更宽的空间1.5em
,你也会得到更高的空间,所以这会影响行距。
While this solution is annoyingly cumbersome, it has the desirable attribute of alwaysworking — which none of the others do.
虽然这个解决方案非常麻烦,但它具有始终有效的理想属性——其他人都没有。
回答by fyngyrz
You could alter your CSS in such:
你可以这样改变你的CSS:
.spanen{word-spacing:.6em;}