如何使用 JavaScript 设置元素的最小高度?
使用 JavaScript 中的 minHeight 属性来设置最大高度。你可以尝试运行以下代码来使用 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>
广告