如何使用 JavaScript 設定以小型大寫字母顯示的字型?


要以小型大寫字母設定字型,請使用fontVariant 屬性。

示例

你可以嘗試執行以下程式碼,使用 JavaScript 來設定字型以顯示為小型大寫字母 −

實際演示

<!DOCTYPE html>
<html>
   <body>
      <h1>Heading 1</h1>
      <p id="myID">
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
      </p>
      <button type="button" onclick="display()">Set Font Family and Font Variant</button>
      <script>
         function display() {
            document.getElementById("myID").style.fontFamily = "verdana,sans-serif";
            document.getElementById("myID").style.fontVariant = "small-caps";
         }
      </script>
   </body>
</html>

更新於:2020-06-23

150 次瀏覽

開啟你的職業生涯

完成課程獲得認證

入門
廣告
© . All rights reserved.