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
广告
© . All rights reserved.