如何使用 JavaScript 設定元素的頂部填充?
在 JavaScript 中使用 `paddingTop` 屬性來設定頂部填充。你可以嘗試執行以下程式碼以使用 JavaScript 設定元素的頂部填充:
示例
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 2px solid #FF0000;
width: 150px;
height: 70px;
}
</style>
</head>
<body>
<div id = "box">This is demo text.</div>
<br><br>
<button type = "button" onclick = "display()">Top Padding</button>
<script>
function display() {
document.getElementById("box").style.paddingTop = "20px";
}
</script>
</body>
</html>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP