Sử dụng minWidth trong JavaScript để đặt chiều rộng tối thiểu. Bạn có thể thử chạy mã sau để đặt chiều rộng tối thiểu của một phần tử bằng JavaScript -
Ví dụ
<!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>