使用JavaScript在元素框外呈现的内容该怎么办?
如果内容在元素框外渲染,请使用overflow属性添加滚动。这将简化访问者阅读整个内容的过程。
示例
您可以尝试运行以下代码,以了解如何使用JavaScript中的溢出属性-
<!DOCTYPE html><html>
<head>
<style>
#box {
width: 450px;
height: 150px;
background-color: orange;
border: 3px solid red;
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.overflow = "scroll";
}
</script>
</body>
</html>
以上是 使用JavaScript在元素框外呈现的内容该怎么办? 的全部内容, 来源链接: utcz.com/z/321857.html