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


当前回答

 , & enp;,  或& # 8194;可以使用。

W3说……

字符实体和分别表示一个en空格和一个em空格,其中en空格是点大小的一半,em空格等于当前字体的点大小。

HTML3的更多信息请访问W3.org

HTML4请在W3.org上阅读更多内容

维基百科上更多

其他回答

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;插入:插入正确的位置

您可以使用一个表并将width属性应用于第一个<td>。

<table>
    <tr>
        <td width="100">Content1</td>
        <td>Content2</td>
    </tr>
    <tr>
        <td>Content3</td>
        <td>Content4</td>
    </tr>
</table>

结果

Content1       Content2
Content3       Content4

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

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

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

如果你正在使用CSS,我建议如下:

p:first-letter  {
   text-indent:1em;
}

这将像传统出版物一样缩进第一行。