Html 制表符空格而不是多个不间断空格(“nbsp”)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1571648/
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
Tab space instead of multiple non-breaking spaces ("nbsp")?
提问by Roch
Is it possible to insert a tab character in HTML instead of having to type
four times?
是否可以在 HTML 中插入制表符而不必键入
四次?
采纳答案by Alohci
It's much cleaner to use CSS. Try padding-left:5em
or margin-left:5em
as appropriate instead.
使用 CSS 更简洁。尝试padding-left:5em
或margin-left:5em
酌情代替。
回答by kristian
It depends on which character set you want to use.
这取决于您要使用的字符集。
There's no tab entity defined in ISO-8859-1 HTML - but there are a couple of whitespace characters other than
such as  
,  
,and  
.
有一个在ISO-8859-1 HTML定义没有标签的实体-但也有比其他几个空格字符
,如 
, 
和 
。
In ASCII, 	
is a tab.
在 ASCII 中,	
是一个制表符。
Hereis a complete listing of HTML entities and a useful discussion of whitespace on Wikipedia.
这是 HTML 实体的完整列表和Wikipedia 上对空白的有用讨论。
回答by Will Robertson
No, Tabis just whitespaceas far as HTML is concerned. I'd recommend an em-spaceinstead which is this big (→| |←) ...typically4 spaces wide— and is input as  
.
不,就HTML 而言,Tab只是空白。我建议使用em-space来代替它这么大 (→| |←) ...通常有4 个空格宽— 并且输入为 
.
You might even be able to get away with using the Unicode character("?
") for it, if you're lucky.
如果幸运的话,您甚至可以避免使用 Unicode字符(" ?
")。
- Here is a list of Space characters and “zero-width spaces” in Unicode.
- 这是Unicode中的空格字符和“零宽度空格”的列表。
回答by WonderWorker
 is the answer.
是答案。
However, they won't be as functional as you might expect if you are used to using horizontal tabulations in word-processors e.g. Word, Wordperfect, Open Office, Wordworth, etc. They are fixed width, and they cannot be customised.
但是,如果您习惯于在文字处理器(例如 Word、Wordperfect、Open Office、Wordworth 等)中使用水平表格,它们将不会像您预期的那样功能。它们是固定宽度的,并且不能自定义。
CSS gives you far greater control and provides an alternative until the W3C provide an official solution.
在 W3C 提供官方解决方案之前,CSS 为您提供了更大的控制权并提供了替代方案。
Example:
例子:
padding-left:4em
..or..
..或者..
margin-left:4em
..as appropriate
..作为适当的
It depends on which character set you want to use.
这取决于您要使用的字符集。
You could set up some tab tags and use them similar to how you would use h tags.
您可以设置一些 tab 标签,并像使用 h 标签一样使用它们。
<style>
tab1 { padding-left: 4em; }
tab2 { padding-left: 8em; }
tab3 { padding-left: 12em; }
tab4 { padding-left: 16em; }
tab5 { padding-left: 20em; }
tab6 { padding-left: 24em; }
tab7 { padding-left: 28em; }
tab8 { padding-left: 32em; }
tab9 { padding-left: 36em; }
tab10 { padding-left: 40em; }
tab11 { padding-left: 44em; }
tab12 { padding-left: 48em; }
tab13 { padding-left: 52em; }
tab14 { padding-left: 56em; }
tab15 { padding-left: 60em; }
tab16 { padding-left: 64em; }
</style>
...and use them like so:
...并像这样使用它们:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tabulation example</title>
<style type="text/css">
dummydeclaration { padding-left: 4em; } /* Firefox ignores first declaration for some reason */
tab1 { padding-left: 4em; }
tab2 { padding-left: 8em; }
tab3 { padding-left: 12em; }
tab4 { padding-left: 16em; }
tab5 { padding-left: 20em; }
tab6 { padding-left: 24em; }
tab7 { padding-left: 28em; }
tab8 { padding-left: 32em; }
tab9 { padding-left: 36em; }
tab10 { padding-left: 40em; }
tab11 { padding-left: 44em; }
tab12 { padding-left: 48em; }
tab13 { padding-left: 52em; }
tab14 { padding-left: 56em; }
tab15 { padding-left: 60em; }
tab16 { padding-left: 64em; }
</style>
</head>
<body>
<p>Non tabulated text</p>
<p><tab1>Tabulated text</tab1></p>
<p><tab2>Tabulated text</tab2></p>
<p><tab3>Tabulated text</tab3></p>
<p><tab3>Tabulated text</tab3></p>
<p><tab2>Tabulated text</tab2></p>
<p><tab3>Tabulated text</tab3></p>
<p><tab4>Tabulated text</tab4></p>
<p><tab4>Tabulated text</tab4></p>
<p>Non tabulated text</p>
<p><tab3>Tabulated text</tab3></p>
<p><tab4>Tabulated text</tab4></p>
<p><tab4>Tabulated text</tab4></p>
<p><tab1>Tabulated text</tab1></p>
<p><tab2>Tabulated text</tab2></p>
</body>
</html>
Run the snippet above to see a visual example.
运行上面的代码片段以查看可视化示例。
Extra discussion
额外讨论
There are no horizontal tabulation entities defined in ISO-8859-1 HTML, however there are some other white-space characters available than the usual  
, for example;  
,  
and the aforementioned  
.
ISO-8859-1 HTML 中没有定义水平制表实体,但是除了通常的 之外还有一些其他的空白字符可用 
,例如; 
, 
以及上述 
。
It's also worth mentioning that in ASCII and Unicode, 	
is a horizontal tabulation.
还值得一提的是,在 ASCII 和 Unicode 中,	
是一种水平制表。
回答by sanjeev51
Below are the 3 different ways provided by HTML to insert empty space
下面是 HTML 提供的 3 种不同的插入空格的方法
- Type
to add a single space. - Type
 
to add 2 spaces. - Type
 
to add 4 spaces.
- 键入
以添加一个空格。 - 键入
 
以添加 2 个空格。 - 键入
 
以添加 4 个空格。
回答by Abhishek Goel
Try 
尝试 
It is equivalent to four
s.
它相当于四个
s。
回答by GonzoKnight
There really isn't any easy way to insert multiple spaces inside (or in the middle) of a paragraph. Those suggesting you use CSS are missing the point. You may not always be trying to indent a paragraph from a side but, in fact, trying to put extra spaces in a particular spot of it.
确实没有任何简单的方法可以在段落内部(或中间)插入多个空格。那些建议你使用 CSS 的人没有抓住重点。您可能并不总是试图从一侧缩进一个段落,但实际上,试图在它的特定位置放置额外的空格。
In essence, in this case, the spaces become the contentand notthe style. I don't know why so many people don't see that. I guess the rigidity with which they try to enforce the separation of style and content rule (HTML was designed to do both from the beginning - there is nothing wrong with occasionally defining style of an uniqueelement using appropriate tags without having to spend a lot more time on creating CSS style sheets and there is absolutely nothing unreadable about it when it's used in moderation. There is also something to be said for being able to do something quickly.) translates to how they can only consider whitespace characters as being used only for style and indentation.
本质上,在这种情况下,空间成为内容而不是风格。我不知道为什么这么多人看不到这一点。我猜他们试图强制执行样式和内容规则分离的刚性(HTML 从一开始就被设计为两者兼而有之 - 偶尔使用适当的标签定义独特元素的样式并没有错,而不必花费更多创建 CSS 样式表的时间,并且当它适度使用时绝对没有什么不可读的。还有一些可以快速做某事的东西要说。)转化为他们如何只能将空白字符视为仅用于样式和缩进。
And when there is no graceful way to insert spaces without having to rely on  
and
tags, I would argue that the resulting code becomes far more unreadible than if there was an appropriately named tag that would have allowed you to quickly insert a large number of spaces (or if, you know, spaces weren't needlessly consumed in the first place).
如果没有优雅的方式来插入空格而不必依赖 
and
标签,我会争辩说,结果代码变得比如果有一个适当命名的标签可以让您快速插入大量空格的情况变得更加难以阅读(或者,如果您知道,空间一开始就没有被不必要地消耗的话)。
As it is though, as was said above, your best bet would be to use  
to insert in the correct place.
尽管如此,如上所述,最好的办法是使用 
插入到正确的位置。
回答by Srikanth Muttavarapu
回答by Rob
I came across this while searching for a method and ended up figuring out my own that seems to work easily for what's wanted. I'm new to posting here so I hope this works... But have this in CSS:
我在寻找一种方法时遇到了这个问题,并最终找出了我自己的方法,它似乎很容易满足我的需要。我是在这里发帖的新手,所以我希望这有效......但是在 CSS 中有这个:
span.tab{
padding: 0 80px; /* Or desired space*/
}
Then in your HTML have this be your "long tab" in mid sentence like I needed:
然后在您的 HTML 中,将其作为我需要的中间句子中的“长标签”:
<span class="tab"></span>
Saves from the amount of
or  
that you'd need.
节省您需要的数量
或数量 
。
Hope this helps someone, cheers!
希望这对某人有所帮助,干杯!
回答by shyammakwana.me
 
,  
,  
or  
can be used.
 
,  
, 
或 
可以使用。
W3 says...
W3 说...
The character entities   and   denote an en space and an em space respectively, where an en space is half the point size and an em space is equal to the point size of the current font.
Even more at Wikipedia
更多在维基百科