是否可以在HTML中插入一个制表符,而不必键入 四次吗?


当前回答

不,就HTML而言,Tab只是空白。我推荐一个这么大的em-space(→| |←)…通常是4个空格宽,输入为 

如果幸运的话,您甚至可以使用Unicode字符(" ")来表示它。

下面是Unicode中空格字符和“零宽度空格”的列表。

其他回答

理想的CSS代码应该是“display”和“min-width”属性的组合…

display: inline-block;
min-width: 10em; // ...for example, depending on the uniform width to be achieved for the items [in a list], which is a common scenario where tab is often needed.

在CSS中有这个:

span.tab{
    padding: 0 80px; /* Or desired space*/
}

然后在你的HTML有这是你的“长标签”在句子中间,就像我需要的:

<span class="tab"></span>

节省&nbsp;或&emsp;这是你需要的。

p {background-color: #FFEEEE;保证金:0;填充:0.5em 0;} < span style=" font - family:宋体;tab-size: 4 " > & # 9 # 9 & # 9←←一个选项卡两个标签# 9 & # 9 & # 9←三个标签# 9 & # 9 & # 9 & # 9←四个选项卡。< / p > < span style=" font - family:宋体;tab-size: 4">←这是一个字符 < span style=" font - family:宋体;</p> . tab-size: 42">&#9←This one has come out too far.</p> . < span style=" font - family:宋体;tab-size: 8">&#9←说!</p>

太懒了;没有“运行代码”):

通过输入&#9在文本中插入制表符,或者(如果您确定文档是UTF-8编码的)按下制表键! 添加空白:预换行;到文本元素的CSS规则,以阻止空格字符(包括制表符)折叠。 添加tab-size: 4;到你的文本元素的CSS规则,以确保你的制表符宽度等于四个标准空格字符。

(在众多的回答和评论中,每一件事都有一些片段和线索,但没有一个像它的措辞那样把它们放在一起来回答这个问题。)

编辑:不幸的是,堆栈代码段将我的Unicode制表符转换为空格!因此,演示的这一部分(第2行)不起作用。如果通过代码格式化器运行代码,可能会遇到类似的问题。&#9避免了这些问题。

在段落中插入多个空格(或在段落中间)确实没有什么简单的方法。那些建议你使用CSS的人没有抓住重点。您可能不总是试图从一个侧面缩进一个段落,但实际上,尝试在它的特定位置放置额外的空格。

In essence, in this case, the spaces become the content and not the 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 unique element 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.

当没有优雅的方式插入空格,而不必依赖&emsp;和,标签,我认为,如果有一个适当命名的标签,允许您快速插入大量的空格(或者如果,您知道,空格一开始就没有被不必要地消耗),那么结果代码将变得更加不可读。

尽管如此,正如上面所说,您最好的选择是使用&emsp;插入:插入正确的位置

有一个简单的css:

white-space: pre;

它保留您在HTML中添加的空格,而不是统一它们。