当文本用JavaScript溢出包含元素时该怎么办?
使用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>热门推荐
10 朋友孩子考试祝福语简短
11 教练生日祝福语 简短独特
12 姐姐女儿结婚祝福语简短
13 十月简短祝福语
14 比较简短浪漫的祝福语
15 许嵩生日祝福语简短
16 顾客简短祝福语大全集
17 雪后早晨简短的祝福语
18 特别的端午祝福语简短