HTML - DOM樣式物件fontVariant屬性



HTML DOM樣式物件fontVariant屬性設定或返回小寫和大寫文字。它將小寫字母轉換為小號大寫字母。

語法

設定fontVariant屬性
object.style.fontVariant= "normal | small-caps | initial | inherit";
獲取fontVariant屬性
object.style.fontVariant;

屬性值

描述
normal 這是預設值,表示普通文字。
small-caps 表示小寫大寫字母的文字。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示字型是普通字型還是小寫大寫字母。

HTML DOM樣式物件“fontVariant”屬性示例

以下示例將文字轉換為小寫大寫字母。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object fontVariant Property
    </title>
</head>
<body>
    <p>Click to make the text in small caps.</p>
    <button onclick="small()">Small-Caps</button>
    <p id="font">Welcome to Tutorials Point.</p>    
    <script>
        function small() {
            document.getElementById("font")
                .style.fontVariant= "small-caps";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
fontVariant 是 1 是 12 是 1 是 1 是 3.5
html_dom_style_object_reference.htm
廣告