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>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP