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


当前回答

在段落中插入多个空格(或在段落中间)确实没有什么简单的方法。那些建议你使用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.

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

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

其他回答

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

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

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

我使用一个不带项目符号的列表来呈现“标签”外观。 (这是我在使用MS Word时有时会做的事情)

在CSS文件中:

.tab {
    margin-top: 0px;
    margin-bottom: 0px;
    list-style-type: none;
}

并且在HTML文件中使用无序列表:

This is normal text
<ul class="tab">
    <li>This is indented text</li>
</ul>

这个解决方案的美妙之处在于,您可以使用嵌套列表进一步缩进。

一个新手在这里说话,所以如果有任何错误,请评论。

在CSS中有这个:

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

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

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

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

我们可以像这样使用style="white-space:pre":

<p>Text<tab style="white-space:pre">        </tab>: value</p>
<p>Text2<tab style="white-space:pre">   </tab>: value2</p>
<p>Text32<tab style="white-space:pre">  </tab>: value32</p>

里面的空白处填满了制表符,制表符的数量取决于文本。

它看起来是这样的:

Text    : value
Text2   : value2
Text32  : value32

我只想建议:

/* In your CSS code: */
pre
{
    display:inline;
}

<!-- And then, in your HTML code: -->

<pre>    This text comes after four spaces.</pre>
<span> Continue the line with other element without braking </span>