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