HTML - DOM Style 物件 borderImage 屬性



HTML DOM Style 物件**borderImage**屬性設定或返回元素的邊框影像。它是一個簡寫屬性,用於設定其他五個屬性:**borderImageSource**、**borderImageSlice**、**borderImageWidth**、**borderImageOutset**和**borderImageRepeat**。

語法

設定 borderImage 屬性
object.style.borderImage= "source | slice | width | outset | repeat | initial | inherit";
獲取 borderImage 屬性
object.style.borderImage;

屬性值

描述
borderImageSource 它指定要作為邊框使用的影像路徑。其預設值為 none。
borderImageSlice 它指定影像邊框的內偏移量。其預設值為 100%。
borderImageWidth 它指定影像邊框的寬度。其預設值為 1。
borderImageOutset 它指定影像邊框區域超出邊框框的擴充套件量。其預設值為 0。
borderImageRepeat 它指定影像邊框是否應為圓形、重複或拉伸。其預設值為 stretch。
initial 它用於將此屬性設定為其預設值。
inherit 它用於繼承其父元素的屬性。

返回值

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

HTML DOM Style 物件“borderImage”屬性示例

以下示例說明如何新增和更改邊框影像。

新增邊框影像

以下示例說明如何向元素新增邊框影像。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML - DOM Style Object borderImage Property
    </title>
    <style>
        #image {
            border: 15px solid transparent;
            padding: 12px;
            width: 100px;
        }
    </style>
</head>
<body>
    <p>
        Click to add the border image
    </p>
    <button onclick="fun()">
        Add Border Image
    </button>
    <div id="image">
        This is a sample paragraph. 
        Here is another line.
    </div>
    <script>
        function fun() {
            document.getElementById("image").style.borderImage =
                "url('/images/blockchain.png') 20 round";
        }
    </script>
</body>
</html>

更改邊框影像

以下示例說明如何更改元素的現有邊框影像。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML - DOM Style Object borderImage Property
    </title>
    <style>
        #image {
            border: 15px solid transparent;
            padding: 12px;
            border-image: url("/images/blockchain.png") 20 stretch;
            width: 100px;
        }
    </style>
</head>
<body>
    <p>
        Click to chnage the border image
    </p>
    <button onclick="fun()">
        Change Border Image
    </button>
    <div id="image">
        This is a sample paragraph. 
        Here is another line.
    </div>
    <script>
        function fun() {
            document.getElementById("image").style.borderImage =
                "url('/images/mongodb.png') 20 round";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
borderImage 是 16 是 12 是 15 是 6 是 11
html_dom_style_object_reference.htm
廣告