คุณสมบัติ minHeight สไตล์ DOM ส่งกลับและแก้ไขความสูงขั้นต่ำขององค์ประกอบในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
-
คืนค่า minHeight
object.style.minHeight
-
แก้ไขความสูงขั้นต่ำ
object.style.minHeight = “value”
คุณค่า
ในที่นี้ ค่าสามารถเป็น −
| ค่า | คำอธิบาย |
|---|---|
| สืบทอด | รับค่าคุณสมบัตินี้จากองค์ประกอบหลัก |
| ค่าเริ่มต้น | ตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| ความยาว | ตั้งค่าเป็นหน่วยความยาว |
| percentage(%) | ตั้งค่าเป็นเปอร์เซ็นต์ความสูงขององค์ประกอบหลัก |
ตัวอย่าง
มาดูตัวอย่างคุณสมบัติ minHeight สไตล์ −
<!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: 300px;
}
.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 minHeight 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 minHeight</button>
<script>
function add() {
document.querySelector('p').style.minHeight = "300px";
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

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