tab-size
Experimental: 这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
CSS 属性 tab-size
用于自定义制表符 (U+0009
) 的宽度。
/* <integer> values */
tab-size: 4;
tab-size: 0;
/* <length> values */
tab-size: 10px;
tab-size: 2em;
/* Global values */
tab-size: inherit;
tab-size: initial;
tab-size: unset;
语法
值
形式语法
示例
pre {
tab-size: 4; /* 将制表符宽度设为 4 个空格 */
}
pre {
tab-size: 0; /* 移除缩进效果 */
}
pre {
tab-size: 2; /* 将制表符宽度设为 2 个空格 */
}
在线演示
本示例比较了默认制表符宽度和自定义制表符宽度。注意 white-space
被设置为 pre
以防止制表符收起。
HTML
<p>no tab</p>
<p>	default tab size of 8 spaces</p>
<p class="custom">	custom tab size of 3 spaces</p>
<p> 3 spaces, equivalent to the custom tab size</p>
CSS
p {
white-space: pre;
}
.custom {
-moz-tab-size: 3;
tab-size: 3;
}
结果
规范
Specification |
---|
CSS Text Module Level 3 # tab-size-property |
浏览器兼容性
BCD tables only load in the browser
参见
- Controlling size of a tab character (U+0009),Anne van Kesteren 发送给 CSSWG 的一封电子邮件。