在HTML中将Tab字符(在PRE元素中)呈现为4个空格? [英] Render a Tab character (in PRE element) as 4 spaces in HTML?

查看:711
本文介绍了在HTML中将Tab字符(在PRE元素中)呈现为4个空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

指定标签宽度?

我需要在预标签。标签的HTML字符是	 ,但是在我试过的所有浏览器中,它呈现为8个空格。

I need to print a tab character in a pre tag. The HTML character for tab is 	 but on all browsers I tried it renders to look like 8 spaces.

是否有一种方法可以调整它,使其成为4个空格的宽度,或者是否有另一个HTML字符,我可以使用4个空格?

Is there a way to adjust this to render to be the width of 4 spaces or is there another HTML character I can use that is 4 spaces?

推荐答案

虽然我同意第一个答案,你可能只需要放4个空格,但似乎对 tab-size CSS中的属性(尽管缺少IE支持):



While I agree with the first answer that you might as well just put 4 spaces, there does seem to be some support for a tab-size property within CSS (though IE support is lacking):

pre {
    -moz-tab-size:    4; /* Firefox 4+ */
    -o-tab-size:      4; /* Opera 11.5 & 12.1 only */
    tab-size:         4; /* Chrome 21+, Safari 6.1+, Opera 15+ */
}

使用 white-space:pre 或 white-space:pre-wrap (或者在 < pre> tags)。

Only effective using white-space: pre or white-space: pre-wrap (or within <pre> tags).

  • W3C specification
  • jsFiddle demonstration
  • Browser support

这篇关于在HTML中将Tab字符(在PRE元素中)呈现为4个空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆