如何用 JavaScript 設定元素的底部內邊距?


要設定底部內邊距,請在 JavaScript 中使用 paddingBottom 屬性。

示例

你可以嘗試執行以下程式碼來返回使用 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()">Bottom padding</button>
     
      <script>
         function display() {
            document.getElementById("box").style.paddingBottom = "100px";
         }
      </script>
   </body>
</html>

更新日期: 2020 年 6 月 23 日

577 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

立即開始
廣告
© . All rights reserved.