CSS - font-size-adjust 屬性



CSS 的font-size-adjust屬性用於調整元素的字型大小,以便在更改字體系列時保持一致的可讀性。它有助於確保文字在不同字型下的顯示大小相似,這在使用備用字型時尤其有用。

語法

font-size-adjust: none | number | initial | inherit;

屬性值

描述
none 指定不根據 x-height 進行字型大小調整。預設值。
數字 指定一個數值,表示縱橫比值,即字型 x-height 與字體系列屬性指定的字型 x-height 的比率。
initial 將屬性設定為其初始值。
inherit 從父元素繼承屬性。

CSS 字型大小調整屬性示例

以下示例說明了使用不同值的font-size-adjust屬性。

使用 none 值的字型大小調整屬性

為了防止根據字型的縱橫比進行任何調整,並直接使用指定的字型大小,而不根據字型的 x-height 修改它,我們將font-size-adjust屬性的值設定為none。這是預設值。以下示例顯示了這一點。

示例

<!DOCTYPE html>
<html>

<head>

   <style>
      body {
         font-family: Arial, sans-serif;
         font-size: 20px;
      }

      .adjusted {
         font-family: "Georgia", serif;
         font-size: 20px;
         font-size-adjust: none;
      }
   </style>
</head>

<body>
   <h2>
      CSS font-size-adjust property
   </h2>
   <p>
      This is text using the default font family (Arial)
      with a font size of 20px.
   </p>
   <p class="adjusted">
      This is text using Georgia with font-size-adjust
      set to none. The font size is not adjusted relative
      to Georgia's x-height.
   </p>
</body>

</html>

使用數值的字型大小調整屬性

為了確保在使用 x-height 不同的字型切換時文字保持一致的可讀性和大小,我們將一個正值(例如 0.25、1 等)指定給font-size-adjust屬性。該值確保使用下一個字型渲染的文字與第一個字型的大小一致。以下示例顯示了這一點。

示例

<!DOCTYPE html>
<html>

<head>
   <style>
      body {
         font-family: Arial, sans-serif;
         font-size: 20px;
      }

      .adjusted {
         font-family: "Georgia", serif;
         font-size: 20px;
         font-size-adjust: 0.5;
      }
   </style>
</head>

<body>
   <h2>
      CSS font-size-adjust property
   </h2>
   <p>
      This is text using the default font family.
   </p>
   <p class="adjusted">
      This is text using Georgia with font-size-adjust applied.
   </p>
</body>

</html>

注意:只有 Firefox 瀏覽器支援font-size-adjust屬性。

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
font-size-adjust 不支援 不支援 3.0 不支援 不支援
css_properties_reference.htm
廣告