HTML DOM 样式 borderLeftColor 属性

htmldomweb developmentfront end technology更新于 2024/3/9 19:56:17

HTML DOM borderLeftColor 属性用于获取或设置元素左边框的颜色。

以下是语法 −

设置 borderImageWidth 属性 −

object.style.borderLeftColor = "color|transparent|initial|inherit"

以上属性的解释如下 −

值描述
color用于指定左边框颜色。默认颜色设置为黑色
transparent使左边框颜色透明,可以看到底层内容。
initial将此属性设置为默认值。
inherit继承父级属性值。

让我们看一个 borderLeftColor 属性的示例 −

示例

<!DOCTYPE html>
<html>
<head>
<style>
   #IMG1{
      border-left:solid 8px;
      border-left-color: orange;
   }
</style>
<script>
   function changeBorderLeft(){
      document.getElementById("IMG1").style.borderLeftColor="lightgreen";
      document.getElementById("Sample").innerHTML="The border left color is now changed to green";
   }
</script>
</head>
<body>
<img id="IMG1" src="https://www.cainiaomax.com/tensorflow/images/tensorflow-mini-logo.jpg?auto=compress&cs=tinysrgb&dpr=2&h=550&w=150">
<p>Change the above image border left color by clicking the below button</p>
<button onclick="changeBorderLeft()">Change Border Color</button>
<p id="Sample"></p>
</body>
</html>

输出

点击"更改边框颜色"按钮 −

在上面的例子中 −

我们创建了一个 id 为"DIV1"的图像元素,并为其应用了 CSS 样式。该 CSS 样式指定了左边框样式和左边框颜色。

#IMG1 {
   border-left:solid 8px;
   border-left-color: orange;
}
<img id="IMG1" src=" https://www.cainiaomax.com/tensorflow/images/tensorflow-mini-logo.jpg?auto=compress&cs=tinysrgb&dpr=2&h=550&w=150">

然后我们创建了一个名为 “更改边框颜色” 的按钮,当用户点击该按钮时,会执行 changeBorderLeft() 方法 −

<button onclick="changeBorderLeft()">更改边框颜色</button>

changeBorderLeft() 方法获取 <img>使用 getElementById() 方法获取 ID 为"IMG1"的元素,并将其 borderLeftColor 样式属性设置为 lightgreen。这会将左边框颜色更改为 lightgreen,并使用其 innerHTML 属性在 ID 为"Sample"的段落中显示此更改 −

function changeBorderLeft(){
   document.getElementById("IMG1").style.borderLeftColor="lightgreen";
   document.getElementById("Sample").innerHTML="The border left color is now changed to green";
}

相关文章


有用资源