ใช้ textOverflow คุณสมบัติเพื่อตอบโต้ปัญหาข้อความล้น เพิ่มจุดไข่ปลาหากข้อความล้นองค์ประกอบที่มี
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้ว่าต้องทำอะไรเมื่อข้อความล้นองค์ประกอบที่มีด้วย JavaScript -
<!DOCTYPE html>
<html>
<head>
<style>
#myID {
border: 2px solid blue;
background-color: gray;
overflow: hidden;
text-overflow: visible;
width: 200px;
white-space: nowrap;
}
</style>
</head>
<body>
<button onclick = "display()"> Click </button>
<div id = "myID">
This is Demo Text! This is Demo Text! This is Demo Text!<br>
This is Demo Text! This is Demo Text! This is Demo Text!<br>
This is Demo Text! This is Demo Text! This is Demo Text!<br>
This is Demo Text! This is Demo Text! This is Demo Text!<br>
</div>
<script>
function display() {
document.getElementById("myID").style.textOverflow = "ellipsis";
}
</script>
</body>
</html>