HTML - DOM樣式物件borderImageWidth屬性



HTML DOM樣式物件**borderImageWidth**屬性設定或返回圖片邊框的寬度。其預設值為1。

語法

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

設定borderImageWidth屬性
object.style.borderImageWidth= "length | number | percentage | auto | initial | inherit";
獲取borderImageWidth屬性
object.style.borderImageWidth;

屬性值

描述
長度 它以px為單位指定邊框寬度。
數字 它指定相應邊框寬度的倍數。其預設值為1。
百分比 它表示邊框影像區域,其中水平偏移量用於寬度,垂直偏移量用於高度。
auto 它將邊框寬度設定為相應影像切片的固有寬度或高度。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的borderImageWidth屬性。

HTML DOM樣式物件'borderImageWidth'屬性示例

以下示例演示如何新增、更改和獲取borderImageWidth屬性。

新增邊框影像寬度

以下示例新增邊框影像寬度並獲取寬度值。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object borderImageWidth Property
    </title>
    <style>
        #width {
            border: 20px solid transparent;
            margin: 20px;
            border-image: url("/images/blockchain.png") 30 round;
        }
    </style>
</head>
<body>
    <p>Click to change Width</p>
    <button onclick="fun()">Add</button>
    <button onclick="funTwo()">Change</button>
    <br><br><br>
    <p id="width">
        This is a sample paragraph containing some 
        text. This paragraph is created only for example.
    </p>
    <p id="ex"></p>
    <script>
        function fun() {
            let x=document.getElementById("width")
                .style.borderImageWidth = "10px 40px";
            document.getElementById("ex").innerHTML=x;
        }
        function funTwo() {
            let x=document.getElementById("width")
                .style.borderImageWidth = "0.5";
            document.getElementById("ex").innerHTML=x;
        }
    </script>
</body>
</html>

設定邊框影像寬度

在以下示例中,我們將borderImageWidth的值設定為auto和百分比。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object borderImageWidth Property
    </title>
    <style>
        #width {
            border: 20px solid transparent;
            margin: 20px;
            border-image: url("/images/blockchain.png") 30 round;
            border-image-width: 10px 40px;
        }
    </style>
</head>
<body>
    <p>Click to change Width</p>
    <button onclick="fun()">
        Change in Percentage
    </button>
    <button onclick="funTwo()">Auto</button>
    <br><br><br>
    <p id="width">
        This is a sample paragraph containing some 
        text. This paragraph is created only for example.
    </p>
    <p id="ex"></p>
    <script>
        function fun() {
            let x=document.getElementById("width")
                .style.borderImageWidth = "15% 25%";
            document.getElementById("ex").innerHTML=x;
        }
        function funTwo() {
            let x=document.getElementById("width")
                .style.borderImageWidth = "auto";
            document.getElementById("ex").innerHTML=x;
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
borderImageWidth 是 15 是 12 是 13 是 6 是 15
html_dom_style_object_reference.htm
廣告