如何使用 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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP