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


当前回答

尽管在HTML3中引入了<tab>标签,但它从未进入浏览器。我一直认为这是一种遗憾,因为如果我们拥有它,在许多情况下生活会轻松得多。但是你可以很容易地纠正这个错误,给你一个假的<tab>标签。在你的HTML头部或CSS中添加以下内容(没有样式标签):

<style>
    tab { padding-left: 4em; }
</style>

从那时起,当你需要在你的文档中添加一个选项卡时,把<tab>放在那里。它不是一个真正的制表符,因为它不与制表符标记对齐,但它可以满足大多数需求,而不必为笨拙的字符实体或跨度而犹豫不决。它使检查源代码变得非常容易,并且在你不想使用表格或其他更复杂的“解决方案”的地方格式化简单的东西。

这个解决方案的一个优点是,您可以快速搜索/替换文本文档,用<tab>标记替换所有tab。

你可以定义一堆真正的绝对位置制表符,然后在需要的地方使用适当的制表符(例如<tab2>或<tab5>或其他),但我还没有找到一种方法来做到这一点,而不缩进后续行。

其他回答

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

这是一个很难看的解决方法,但是你可以这样做

var tab = '&nbsp;&nbsp;&nbsp;&nbsp;';

然后在字符串中使用tab变量。

好吧,如果你只需要在一整段的某一行开头有一个很长的空白,那么这可能是一个解决方案:

<span style='display:inline-block;height:1em;width:4em;'>&nbsp;</span>

如果写的内容太多,或者在很多地方都需要这样的制表符,那么您可以这样做

<span class='tab'>&nbsp;</span>

然后将其包含到CSS中:

span.tab {display:inline-block;height:1em;width:4em;}

只有“pre”标签:

<pre>Name:      Waleed Hasees
Age:        33y
Address:    Palestine / Jein</pre>

你可以在这个标签上应用任何CSS类。

如果你只是想缩进段落中的第一句话,你可以用一个CSS小技巧来做到这一点:

p:first-letter {
    margin-left: 5em;
}