หากเนื้อหาล้น วิธีแก้ปัญหาด้วย overflowX คุณสมบัติเพื่อแก้ปัญหาขอบซ้าย/ขวาและตั้งค่าการเลื่อน การเพิ่มสกรอลล์ทำให้ผู้เข้าชมสามารถอ่านเนื้อหาทั้งหมดได้อย่างง่ายดาย
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้ว่าต้องทำอะไรกับขอบซ้าย/ ขวาของเนื้อหาบนโอเวอร์โฟลว์ด้วย JavaScript -
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 350px;
height: 150px;
background-color: orange;
border: 3px solid red;
white-space: nowrap;
margin-left: 20px;
}
</style>
</head>
<body>
<p>Click to use overflow property and set scroll.</p>
<button type="button" onclick="display()">Set Scroll</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>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
</div>
<br>
<br>
<script>
function display() {
document.getElementById("box").style.overflowX = "scroll";
}
</script>
</body>
</html>