JavaScript溢出时应如何处理内容的左/右边缘?
如果内容溢出,则使用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>热门推荐
10 上班收到花束祝福语简短
11 同事男生节祝福语简短
12 女生 节日祝福语简短大气
13 幼儿祝福语押韵句子简短
14 朋友家住豪宅祝福语简短
15 经典送别祝福语大全简短
16 圣诞祝福语简短小学
17 男朋友新年祝福语简短
18 看病贺卡祝福语简短英文