คุณสมบัติ minWidth สไตล์ DOM ส่งคืนและแก้ไขความกว้างขั้นต่ำขององค์ประกอบในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
-
คืนค่า minWidth
object.style.minWidth
-
กำลังแก้ไข minWidth
object.style.minWidth = “value”
คุณค่า
ในที่นี้ ค่าสามารถเป็น −
| ค่า | คำอธิบาย |
|---|---|
| สืบทอด | รับค่าคุณสมบัตินี้จากองค์ประกอบหลัก |
| ค่าเริ่มต้น | ตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| ความยาว | ตั้งค่าเป็นหน่วยความยาว |
| percentage(%) | ตั้งค่าเป็นเปอร์เซ็นต์ความกว้างขององค์ประกอบหลัก |
ตัวอย่าง
ให้เรามาดูตัวอย่างคุณสมบัติ minWidth สไตล์ −
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background-image: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);
height: 100vh;
}
p {
border: 2px solid #fff;
width: 30%;
}
.btn {
background: coral;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style minWidth Property Example</h1>
<p>
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
</p>
<button onclick="add()" class="btn">Set minWidth</button>
<script>
function add() {
document.querySelector('p').style.minWidth = "300px";
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

คลิกที่ “ตั้งค่าความกว้างขั้นต่ำ ” เพื่อกำหนดความกว้างขั้นต่ำขององค์ประกอบย่อหน้า
