如何利用 JavaScript 设置元素周围边框的宽度?
如需设置边框,请使用 outlineWidth 属性。您可以尝试运行以下代码,用 JavaScript 设置元素周围边框的宽度 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 450px;
background-color: orange;
border: 3px solid red;
margin-left: 20px;
}
</style>
</head>
<body>
<p>Click below to add Outline Width.</p>
<div id="box">
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
</div>
<br>
<button type="button" onclick="display()">Set Outline Width</button>
<br>
<script>
function display() {
document.getElementById("box").style.outlineColor = "#5F5F5F";
document.getElementById("box").style.outlineStyle = "solid";
document.getElementById("box").style.outlineWidth = "7px";
}
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP