如何使用JavaScript设置元素的最小宽度?
使用JavaScript中的minWidth属性设置最小宽度。您可以尝试运行以下代码以使用JavaScript设置元素的最小宽度-
示例
<!DOCTYPE html> <html> <head> <style> #box { width: 50%; background-color: gray; } </style> </head> <body> <p>Click below to set Minimum width.</p> <button type="button" onclick="display()">Min Width</button> <div id="box"> <p>This is a div. This is a div. 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. This is a div. This is a div.</p> <p>This is a div. This is a div. 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. This is a div. This is a div.</p> <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p> </div> <br> <script> function display() { document.getElementById("box").style.minWidth = "500px"; } </script> </body> </html>