0
我想为span元素设置左侧和顶部CSS属性。这在HTML4页面中工作正常,但在HTML5页面上存在问题。代码已发布在jsfiddle https://jsfiddle.net/arunn/pxxgtnqf/上,它显示了HTML5页面中的行为。我将这里的代码发布到HTML4行为。html5页面元素CSS:左侧属性不起作用
<!DOCTYPE>
<html>
<body>
<span id='hello' style='position:absolute;top:100px;'>hello</span>
</body>
<script type="text/javascript">
document.getElementById("hello").style.left = 100;
document.getElementById("hello").style.top = 100;
</script>
</html>
同时需要分配后添加'+ “PX”' –