如何使用 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>

更新於:2020 年 6 月 23 日

490 次瀏覽

開啟你的 職業 生涯

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.