HTML - DOM Style 对象 fontStyle 属性



HTML DOM Style 对象的 **fontStyle** 属性设置或返回元素的字体样式。

语法

设置 fontStyle 属性
object.style.fontStyle= "normal | italic | oblique | initial | inherit";
获取 fontStyle 属性
object.style.fontStyle;

属性值

描述
normal 这是默认值,表示元素的普通字体。
italic 表示斜体字体。
oblique 表示倾斜字体。
initial 用于将此属性设置为其默认值。
inherit 用于继承其父元素的属性。

返回值

它返回一个字符串值,表示元素的字体样式属性。

HTML DOM Style 对象“fontStyle”属性示例

以下示例实现了字体样式属性的斜体、普通和倾斜值。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object fontStyle Property
    </title>
</head>
<body>
    <p>Click to change font style.</p>
    <button onclick="italic()">Italic</button>
    <button onclick="normal()">Normal</button>
    <button onclick="oblique()">Oblique</button>
    <p id="font">Welcome to Tutorials Point.</p>    
    <script>
        function italic() {
            document.getElementById("font")
                .style.fontStyle= "italic";
        }
        function normal() {
            document.getElementById("font")
                .style.fontStyle= "normal";
        }
        function oblique() {
            document.getElementById("font")
                .style.fontStyle= "oblique";
        }
    </script>
</body>
</html>

支持的浏览器

属性 Chrome Edge Firefox Safari Opera
fontStyle 是 1 是 12 是 1 是 1 是 7
html_dom_style_object_reference.htm
广告