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

更新於: 23-Jun-2020

577 次瀏覽

開始你的職業生涯

透過完成課程獲得認證

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