如何利用 JavaScript 設定元素的最小高度?
在 JavaScript 中使用<em>minHeight</em>屬性設定最大高度。你可以嘗試執行以下程式碼,利用 JavaScript 設定元素的最小高度 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 300px;
background-color: gray;
overflow: auto;
}
</style>
</head>
<body>
<p>Click below to set Minimum height.</p>
<button type="button" onclick="display()">Min 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.minHeight = "400px";
}
</script>
</body>
</html>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP