如何通过javascript更改标题的边距

我想通过 javascript 更改我的 h1 边距,但它不起作用

我的代码:

<script>
  document.getElementById("h1").style.marginLeft = "250px";
</script>

<h1>Shop till<br>you drop</h1>

回答

您可以看到,如果您的函数放在它作用的元素之后,它确实可以工作。

h1 {
  position: absolute;
  text-align: center;
  top: 10px;
  color: #E95928;
  font-family: Helvetica;
  font-weight: bold;
  font-size: 6vw;
}
<h1>Shop 'til<br>you drop</h1>

<script>
  document.getElementById("h1").style.marginLeft = "250px";
</script>


以上是如何通过javascript更改标题的边距的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>