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


当前回答

如果您只需要一个选项卡,那么下面的选项卡对我有用。

<style>
  .tab {
    position: absolute;
    left: 10em;
   }
</style>

使用HTML的内容如下:

<p><b>asdf</b> <span class="tab">99967</span></p>
<p><b>hjkl</b> <span class="tab">88868</span></p> 

你可以添加更多的“标签”通过添加额外的“标签”样式和改变HTML,如:

<style>
  .tab {
    position: absolute;
    left: 10em;
   }
  .tab1 {
    position: absolute;
    left: 20em;
   }
</style>

使用HTML的内容如下:

<p><b>asdf</b> <span class="tab">99967</span><span class="tab1">hear</span></p>
<p><b>hjkl</b> <span class="tab">88868</span><span class="tab1">here</span></p>

其他回答

而不是写&nbsp;四个时间为空格等于制表符,可以写&emsp;一次。

在段落中插入多个空格(或在段落中间)确实没有什么简单的方法。那些建议你使用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与行内样式。我不得不这样做,因为我正在处理一个纯文本字符串,需要用4个空格(appx)替换\t。我不能使用&nbsp;在进一步的过程中,它们被解释,所以最后的标记有非内容空间。

HTML:

<span style="padding: 0 40px">&nbsp;</span>

我在一个php函数中使用了它:

$message = preg_replace('/\t/', '<span style="padding: 0 40px">&nbsp;</span>', $message);

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

<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;}