我想通过 javascript 更改我的 h1 边距,但它不起作用
我的代码:
<script>
document.getElementById("h1").style.marginLeft = "250px";
</script>
<h1 id="h1" style="position: absolute; text-align: center; top: 100px; color: #E95928; font-family:Helvetica; font-weight: bold; font-size:6vw; ">Shop till<br>you drop</h1>Run Code Online (Sandbox Code Playgroud)
您可以看到,如果您的函数放在它作用的元素之后,它确实可以工作。
h1 {
position: absolute;
text-align: center;
top: 10px;
color: #E95928;
font-family: Helvetica;
font-weight: bold;
font-size: 6vw;
}Run Code Online (Sandbox Code Playgroud)
<h1 id="h1">Shop 'til<br>you drop</h1>
<script>
document.getElementById("h1").style.marginLeft = "250px";
</script>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31 次 |
| 最近记录: |