<html>
<head>
<style>
#myDIV {
position: relative;
width: 100px;
height: 100px;
background-color: coral;
color: white;
}
</style>
</head>
<body>
<h1>使用 JavaScript 更改 top 属性</h1>
<p>单击“试一试”按钮将 DIV 元素从其原始位置向下放置 100 像素:</p>
<p><strong>注意:</strong>如果 position 属性设置为“static”,则 top 属性无效。</p>
<button onclick="myFunction()">试一试</button>
<div id="myDIV">
<h1>myDIV</h1>
</div>
<script>
function myFunction() {
document.getElementById("myDIV").style.top = "100px";
}
</script>
</body>
</html>