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


在 JavaScript 中使用 marginBottom 屬性,來設定底部邊距。

示例

您可以嘗試執行以下程式碼,用 JavaScript 設定元素底部邊距 −

線上演示

<!DOCTYPE html>
<html>
   <body>
      <p id="myID">This is demo text.</p>
      <button type="button" onclick="display()">Set bottom margin</button>
      <script>
         function display() {
            document.getElementById("myID").style.marginBottom = "95px";
         }
      </script>
   </body>
</html>

更新時間:2020 年 6 月 23 日

602 瀏覽

開啟你的 職業生涯

透過完成本課程獲得認證

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