Html 没有 的HTML中单词之间的多个空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4503001/
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
Multiple Spaces Between Words in HTML without
提问by Ted Scheckler
I'm using a barcode font "Free 3 of 9 Extended Regular" and the print out needs to have multiple spaces in some cases, to match the number of characters in the field. Example:
我正在使用条形码字体“Free 3 of 9 Extended Regular”,在某些情况下,打印输出需要有多个空格,以匹配字段中的字符数。例子:
*AA-XXXX *"
(four spaces follow the item number to make the 12 characters. The barcode reader will give me an error if there are less characters.
(商品编号后面有四个空格组成12个字符。如果字符少,条码阅读器会给我一个错误。
nbsp;
will force multiple spaces, however, IE and Firefox both display those as standard font spaces and do not use the barcode font. The barcode displays as broken up between the non-space characters. (Incidentally, only IE 6 does display nbsp;
in the proper font.) If I use a regular space, it trims the number of spaces down and displays only one.
nbsp;
将强制使用多个空格,但是,IE 和 Firefox 都将这些显示为标准字体空间,并且不使用条码字体。条形码显示为在非空格字符之间断开。(顺便说一句,只有 IE 6 确实nbsp;
以正确的字体显示。)如果我使用常规空格,它会减少空格数并只显示一个。
Thanks in advance.
提前致谢。
回答by Gabriele Petrioli
Look at the white-space
css property
查看white-space
css属性
Using
使用
.barcode{
white-space:pre; /* or pre-wrap if you want wrapping to still work. */
}
and
和
<span class="barcode">*AA-XXXX *"</span>
will do the trick.
会做的伎俩。
.barcode{
font-family:Courier;
white-space:pre; /* or pre-wrap if you want wrapping to still work.*/
}
<span class="barcode">*AA-XXXX *"</span>
external demo: http://www.jsfiddle.net/gaby/Z3gkq/
回答by Quentin
Use <pre>
when whitespace is significant.
<pre>
当空格很重要时使用。
回答by Mahmoud Farahat
you can replace all spaces with  
你可以用  
回答by Parley Hammon
I like to use this special white-space that HTML and JavaScript does not detect as white-space. ->"?"
我喜欢使用这种特殊的空白,HTML 和 JavaScript 不会将其检测为空白。->“?”
It looks better on the code end too.
它在代码端看起来也更好。
UPDATE
更新
Looks like stack over flow replaces it with a regular space so here is the ASCII code for it
看起来堆栈溢出用常规空格替换了它,所以这里是它的 ASCII 代码
Dec 160 Hex A0 Oct 240
12 月 160 日十六进制 A0 240 年 10 月