<html>
<head>
<style?type='text/css'>
div?{?position:?relative;?border:?4px?solid?#ccc;?height:?200px;?overflow:?hidden;}
p?{?position:?absolute;?height:?100px;?line-height:?100px;border:?2px?solid?blue;}
</style>
</head>
<body>
<div>
<p?id='a'style='left:-20px;?z-index:?10;'>12342</p>
</div>
</body>
<script?type='text/javascript'>
function?$id(id){?return?document.getElementById(id);};
var?a?=?$id('a').offsetLeft;
alert(a);
</script>
</html>我實(shí)驗(yàn)了一下,當(dāng)父元素設(shè)置overflow:hidden;的時(shí)候,offsetLeft為正就style.left加父元素的邊框;為負(fù)就減。而父元素沒(méi)設(shè)置overflow;hidden的時(shí)候,offsetLeft和style.left數(shù)值上是相等的。這是為什么????
為什么a.offsetLeft為-24px????
上帝子民Chris
2016-10-03 17:44:15