如何處理超出元素框並利用 JavaScript 渲染的內容?
如果內容已超出元素框並渲染,使用 overflow 屬相新增一個捲軸。這將緩解訪問者閱讀全部內容的過程。
示例
您可以嘗試執行以下程式碼,以瞭解如何在 JavaScript 中使用 overflow 屬性 −
<!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>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP