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


当前回答

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

var tab = '    ';

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

其他回答

CSS

<html>
<head>
<style>
    tab:before
    {
        content: "\00a0\00a0\00a0\00a0";
    }
</style>
</head>

HTML

<body>
    <tab> #include &lt; stdio.h &gt; <br>
    <tab> <br>
    <tab> int main (void) <br>
    <tab> { <br>
    <tab> <tab> printf ("Hello, World!"); <br>
    <tab> <tab> return 0; <br>
    <tab> } <br>
</body>
</html>

呈现

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

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

&ampnbsp单位与字体大小有关。为了理解这种依赖关系,使用CSS/HTML方法考虑em和rem度量单位。

CSS

.tab { margin-left: 1rem; }

HTML

<div class=“tab> ...p and h elements... </div>

显示

1em约等于4 &nbsp;但是,Em unit和&ampnbsp rem unit的显示取决于元素和样式的使用,像这样缩进。

--------h1 indented 1em
--p indented 1em
----h1 indented 1rem
----p indented 1rem

左边距和左填充都有效。在HTML或CSS中没有标签长度单位。可以使用.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标记定义预格式化文本。

<pre>
 This is
preformatted text.
It preserves      both spaces

and line breaks.

</pre>

了解更多关于前标签在这个链接