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将元素设置为不可调整大小。
horizo​​ntal将元素的宽度设置为可调整大小。
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 元素的大小。


相关文章


有用资源