如何使用JavaScript设置元素的最大高度?

使用JavaScript中的maxHeight属性设置最大高度。您可以尝试运行以下代码以使用JavaScript设置元素的最大高度-

示例

<!DOCTYPE html>

<html>

<head>

<style>

   #box {

      width: 300px;

      background-color: gray;

      overflow: auto;

   }

</style>

</head>

<body>

<p>Click below to set Maximum height.</p>

<button type="button" onclick="display()">Max Height</button>

<div id="box">

<p>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.<p>

<p>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.<p>

<p>This is a div. This is a div. This is a div.<p>

</div>

<br>

<script>

   function display() {

      document.getElementById("box").style.maxHeight = "70px";

   }

</script>

</body>

</html>

以上是 如何使用JavaScript设置元素的最大高度? 的全部内容, 来源链接: utcz.com/z/335103.html

回到顶部