HTML DOM Style minHeight 属性

htmlweb developmentfront end technology更新于 2025/6/11 1:48:17

DOM Style minHeight 属性返回并修改 HTML 文档中元素的最小高度。

语法

以下是语法 −

  • 返回 minHeight

object.style.minHeight
  • 修改 minHeight

object.style.minHeight = “value”

值

此处,值可以为 -

值说明
inherit从其父元素继承此属性值。
initial将此属性值设置为其默认值。
length以长度单位设置值。
percentage(%)以父元素的百分比高度设置值。

示例

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

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      background-image: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);
      height: 100vh;
   }
   p {
      border: 2px solid #fff;
      width: 300px;
   }
   .btn {
      background: coral;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
   }
</style>
</head>
<body>
<h1>DOM Style minHeight Property Example</h1>
<p>
   This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
   This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
   This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
</p>
<button onclick="add()" class="btn">Set minHeight</button>
<script>
   function add() {
      document.querySelector('p').style.minHeight = "300px";
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击“设置最小高度”按钮设置段落元素的最小高度 −


相关文章


有用资源