x
 
<!DOCTYPE html>
<html>
<head>
<style> 
#myDIV {
  position: absolute;
  width: 100px;
  height: 100px;
  background-color: coral;
  color: white;
}
</style>
</head>
<body>
<p>点击“试一试”按钮可将 DIV 元素定位到距左边缘 -30 像素的位置:</p>
<p><b>注释:</b>如果 position 属性设置为 “static”,则 left 属性无效。</p>
<button onclick="myFunction()">试一试</button>
<div id="myDIV">
  <h1>myDIV</h1>
</div>
<script>
function myFunction() {
  document.getElementById("myDIV").style.left = "-30px";
}
</script>
</body>
</html>