如何使用JavaScript设置元素的边距?

阅读 633 收藏 0 点赞 0 评论 0

在JavaScript中使用margin属性设置边距。您可以尝试运行以下代码以使用JavaScript设置元素的边距-

示例

<!DOCTYPE html>
<html>
   <body>
      <button type="button" onclick="display()">Set all four margins</button>
      <p id="myID">This is demo text.</p>
      <script>
         function display() {
            document.getElementById("myID").style.margin = "30px 20px 40px 40px";
         }
      </script>
   </body>
</html>
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号