HTML - DOM樣式物件borderLeftWidth屬性



HTML DOM 樣式物件 **borderLeftWidth** 屬性設定或返回元素的左邊框寬度。

語法

以下是獲取或設定 borderLeftWidth 屬性的語法。

設定 borderLeftWidth 屬性
object.style.borderLeftWidth= "thin | medium | thick | length | initial | inherit";
獲取 borderLeftWidth 屬性
object.style.borderLeftWidth;

屬性值

描述
thin 指定元素的細左邊框。
medium 預設值,指定元素的中等左邊框。
thick 指定元素的粗左邊框。
長度 以 CSS 測量單位(如 px)指定左邊框寬度。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的左邊框寬度。

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

以下示例獲取和設定左邊框寬度。

設定元素的左邊框寬度

以下示例說明不同的左邊框寬度值,例如“長度”、“thin”、“medium”和“thick”。

<!DOCTYPE html>
<html lang="en">
<head>
    <Title>
        HTML DOM Style Object borderLeftWidth 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.borderLeftWidth = "10px";
        }
        function thin() {
            document.getElementById("border")
            .style.borderLeftWidth = "thin";
        }
        function medium() {
            document.getElementById("border")
            .style.borderLeftWidth = "medium";
        }
        function thick() {
            document.getElementById("border")
            .style.borderLeftWidth = "thick";
        }
    </script>
</body>
</html>

獲取左邊框寬度值

以下示例返回左邊框寬度的值。

<!DOCTYPE html>
<html lang="en">
<head>
    <Title>
        HTML DOM Style Object borderLeftWidth 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="left"></p>
    <script>
        function length() {
            let x = document.getElementById("border")
                .style.borderLeftWidth = "10px";
            document.getElementById("left").innerHTML = x;
        }
        function thin() {
            let x = document.getElementById("border")
                .style.borderLeftWidth = "thin";
            document.getElementById("left").innerHTML = x;
        }
        function medium() {
            let x = document.getElementById("border")
                .style.borderLeftWidth = "medium";
            document.getElementById("left").innerHTML = x;
        }
        function thick() {
            let x = document.getElementById("border")
                .style.borderLeftWidth = "thick";
            document.getElementById("left").innerHTML = x;
        }
    </script>
</body>
</html>

支援的瀏覽器

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