使用JavaScript中的maxWidth属性设置最大宽度。
您可以尝试运行以下代码以使用JavaScript设置元素的最大宽度-
<!DOCTYPE html> <html> <body> <p>Click below to set Maximum width.</p> <button type="button" onclick="display()">Max Width</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.maxWidth = "80px"; } </script> </body> </html>