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
广告

© . All rights reserved.