คุณสมบัติโอเวอร์โฟลว์สไตล์ DOM ส่งคืนและแก้ไขคุณสมบัติโอเวอร์โฟลว์ CSS ขององค์ประกอบในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
-
กลับมาล้น
object.style.overflow
-
กำลังแก้ไขน้ำล้น
object.style.overflow = “value”
คุณค่า
ค่านี้สามารถเป็น −
| ค่า | คำอธิบาย |
|---|---|
| เลื่อน | คลิปเนื้อหาและแถบเลื่อนจะถูกเพิ่มเมื่อจำเป็น |
| สืบทอด | รับค่าคุณสมบัตินี้จากองค์ประกอบหลัก |
| เริ่มต้น | ตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| อัตโนมัติ | ตัดเนื้อหาและเพิ่มแถบเลื่อนเมื่อจำเป็น |
| ซ่อนอยู่ | ซ่อนการไหลของเนื้อหานอกกล่ององค์ประกอบ |
| มองเห็นได้ | ไม่ตัดเนื้อหาและเนื้อหาจะไหลออกนอกกล่ององค์ประกอบ |
ตัวอย่าง
ให้เรามาดูตัวอย่างคุณสมบัติสไตล์ล้น -
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
}
p {
border: 2px solid #fff;
margin: 1.5rem auto;
height: 100px;
overflow: scroll;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style overflow 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.
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.
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">Change overflow</button>
<script>
function add() {
document.querySelector('p').style.overflow = "hidden";
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

คลิกที่ “เปลี่ยนการล้น ” เพื่อเปลี่ยนค่าของคุณสมบัติ CSS ล้นจาก เลื่อน เพื่อซ่อน .
