试一试
tab-size: 10px;
tab-size: 16px;
tab-size: 24px;
tab-size: 4;
<section id="default-example">
<pre id="example-element">	123</pre>
</section>
#example-element {
border: 1px solid;
}
语法
css
/* <number> 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: revert;
tab-size: revert-layer;
tab-size: unset;
值
正式定义
正式语法
tab-size =
<number [0,∞]> |
<length [0,∞]>
示例
按字符数展开
css
pre {
tab-size: 4; /* Set tab size to 4 characters wide */
}
折叠制表符
css
pre {
tab-size: 0; /* Remove indentation */
}
默认制表符大小与自定义大小
此示例比较了默认制表符大小和自定义制表符大小。请注意,white-space 设置为 pre 以防止制表符折叠。
HTML
html
<p>no tab</p>
<p>	default tab size of 8 characters wide</p>
<p class="custom-number">	custom tab size of 3 characters wide</p>
<p> 3 spaces, equivalent to the custom tab size</p>
<p class="custom-length">	custom tab size of 50px wide</p>
CSS
css
p {
white-space: pre;
}
.custom-number {
tab-size: 3;
}
.custom-length {
tab-size: 50px;
}
结果
规范
| 规范 |
|---|
| CSS Text Module Level 3 # tab-size-property |
浏览器兼容性
加载中…