HTML - DOM Style 对象 borderTopWidth 属性



HTML DOM Style 对象 **borderTopWidth** 属性设置或返回元素的上边框宽度。

语法

设置 borderTopWidth 属性
object.style.borderTopWidth= "thin | medium | thick | length | initial | inherit";
获取 borderTopWidth 属性
object.style.borderTopWidth;

属性值

描述
thin 指定元素的细上边框。
medium 默认值,指定元素的中等上边框。
thick 指定元素的粗上边框。
length 以 CSS 测量单位(如 px)指定上边框宽度。
initial 用于将此属性设置为其默认值。
inherit 用于继承其父元素的属性。

返回值

返回一个字符串值,表示元素的上边框宽度。

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

以下示例获取和设置上边框宽度。

设置元素的上边框宽度

以下示例说明了不同的上边框宽度值,如“length”、“thin”、“medium”和“thick”。

<!DOCTYPE html>
<html lang="en">
<head>
    <Title>
        HTML DOM Style Object borderTopWidth Property
    </Title>
    <style>
        h1 {
            border: solid 1px #04af2f;
        }
    </style>
</head>
<body>
    <p>Click to change the border style.</p>
    <button onclick="length()">Change Width</button>
    <button onclick="thin()">Thin</button>
    <button onclick="medium()">Medium</button>
    <button onclick="thick()">Thick</button>
    <h1 id="border">Welcome to Tutorials Point...</h1>
    <script>
        function length() {
            document.getElementById("border")
                .style.borderTopWidth = "10px";
        }
        function thin() {
            document.getElementById("border")
                .style.borderTopWidth = "thin";
        }
        function medium() {
            document.getElementById("border")
                .style.borderTopWidth = "medium";
        }
        function thick() {
            document.getElementById("border")
                .style.borderTopWidth = "thick";
        }
    </script>
</body>
</html>

获取上边框宽度值

以下示例返回上边框宽度的值。

<!DOCTYPE html>
<html lang="en">
<head>
    <Title>
        HTML DOM Style Object borderTopWidth Property
    </Title>
    <style>
        h1 {
            border: solid 1px #04af2f;
        }
    </style>
</head>
<body>
    <p>Click to change the border style.</p>
    <button onclick="length()">Change Width</button>
    <button onclick="thin()">Thin</button>
    <button onclick="medium()">Medium</button>
    <button onclick="thick()">Thick</button>
    <h1 id="border">Welcome to Tutorials Point...</h1>
    <p id="top"></p>
    <script>
        function length() {
            let x = document.getElementById("border")
                .style.borderTopWidth = "10px";
            document.getElementById("top").innerHTML = x;
        }
        function thin() {
            let x = document.getElementById("border")
                .style.borderTopWidth = "thin";
            document.getElementById("top").innerHTML = x;
        }
        function medium() {
            let x = document.getElementById("border")
                .style.borderTopWidth = "medium";
            document.getElementById("top").innerHTML = x;
        }
        function thick() {
            let x = document.getElementById("border")
                .style.borderTopWidth = "thick";
            document.getElementById("top").innerHTML = x;
        }
    </script>
</body>
</html>

支持的浏览器

属性 Chrome Edge Firefox Safari Opera
borderTopWidth 是 1 是 12 是 1 是 1 是 3.5
html_dom_style_object_reference.htm
广告

© . All rights reserved.