用 CSS tab-size 屬性在 HTML 中設定製表符大小


CSS tab-size 屬性允許我們設定製表符中使用的空格數量。製表符字元的寬度可以輕鬆自定義。為製表符大小設定的值以空格為單位。讓我們看看語法。

語法

 tab-size: value;

上面的值為設定製表符的數字值。

以下示例說明了 CSS tab-size 屬性。

示例

在此,我們使用 tab-size 屬性將製表符大小設定為 32 -

tab-size: 32;

Firefox 的製表符大小也已設定 -

-moz-tab-size: 32;

讓我們看看該示例 -

<!DOCTYPE html>
<html>
<head>
   <style>
      body {
         display: flex;
         flex-direction: column;
      }
      p {
         white-space: pre;
      }
      p:last-of-type {
         tab-size: 32;
         -moz-tab-size: 32;
      }
   </style>
</head>
<body>
   <p>Ut sed felis lobortis, fermentum magna vitae, imperdiet lectus.</p>
   <p>Ut sed felis lobortis, fermentum magna vitae, imperdiet lectus.</p>
</body>
</html>

示例

在此,我們使用 tab-size 屬性將製表符大小設定為 1 -

tab-size: 1;

Firefox 的製表符大小也已設定 -

-moz-tab-size: 1;

讓我們看看該示例 -

<!DOCTYPE html>
<html>
<head>
   <style>
      pre {
         margin: 2%;
         box-shadow: inset 0 0 12px lime;
      }
      p {
         background: lavender;
         tab-size: 1;
         -moz-tab-size: 1;
      }
   </style>
</head>
<body>
   <pre>
      4 tabs of size 1 paragraph
      .|.|.|.
      <p>
         Ut sed felis lobortis, fermentum magna vitae, imperdiet lectus.
      </p>
   </pre>
</body>
</html>

更新於:2023 年 12 月 27 日

537 次瀏覽

開始你職業生涯

完成課程後獲得認證

開始
廣告
© . All rights reserved.