HTML DOM Style resize 属性
htmlweb developmentfront end technology更新于 2025/6/11 3:56:17
HTML DOM Style resize 属性返回并修改元素在 HTML 文档中是否可由用户调整大小。
语法
以下是语法 −
返回 resize
object.style.resize
修改 resize
object.style.resize = “value”
值
此处,值可以为 -
| 值 | 说明 |
|---|---|
| inherit | 从其父元素继承此属性值。 |
| initial | 将此属性值设置为其默认值。 |
| none | 将元素设置为不可调整大小。 |
| horizontal | 将元素的宽度设置为可调整大小。 |
| vertical | 将元素的高度设置为可调整大小。 |
| both | 它将元素的宽度和高度设置为可调整大小。 |
示例
让我们看一个 HTML DOM Style resize 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
}
.resize-div {
border: 2px solid #fff;
margin: 2rem auto;
width: 300px;
overflow: auto;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style resize Property Example</h1>
<div class="resize-div">
<p>I'm a paragraph element with some dummy text.</p>
</div>
<button onclick="add()" class="btn">Set resize</button>
<script>
function add() {
document.querySelector('div').style.resize = "both";
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击"设置调整大小"按钮,让用户调整 div 元素的大小。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

