tab-size
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2021.
tab-size
CSS 属性用于自定义制表符(U+0009)的宽度。
尝试一下
语法
css
/* <integer> 值 */
tab-size: 4;
tab-size: 0;
/* <length> 值 */
tab-size: 10px;
tab-size: 2em;
/* 全局值 */
tab-size: inherit;
tab-size: initial;
tab-size: unset;
取值
形式定义
形式语法
tab-size =
<number [0,∞]> |
<length [0,∞]>
示例
按字符数扩展
css
pre {
tab-size: 4; /* 将制表符大小设置为 4 个字符宽度。 */
}
折叠制表符
css
pre {
tab-size: 0; /* 去除缩进 */
}
与默认尺寸相比较
这个例子比较了默认的制表符大小和自定义的制表符大小。请注意,设置了 white-space
属性为 pre
,以防止制表符折叠。
HTML
html
<p>no tab</p>
<p>	default tab size of 8 characters wide</p>
<p class="custom">	custom tab size of 3 characters wide</p>
<p> 3 spaces, equivalent to the custom tab size</p>
CSS
css
p {
white-space: pre;
}
.custom {
tab-size: 3;
}
结果
规范
Specification |
---|
CSS Text Module Level 3 # tab-size-property |
浏览器兼容性
BCD tables only load in the browser