问题描述:为什么会出现两个按钮并排;而且如果将上面的按钮去掉下面也显示不出来。
(自学基础不扎实)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>offSetParent与offSetleft</title>
<style type="text/css">
#div1{
width: 200px;
height: 200px;
background: #DC143C;
position: absolute;
}
#div2{
width: 100px;
height: 100px;
background:#A9A9A9;
position: absolute;
}
#div3{
width: 50px;
height: 50px;
background:#FF1493;
position: absolute;
left: 100px;
}
</style>
</head>
<body>
<input type="button" id="btn" value="点击我" />
<div id="div1">
<div id="div2">
<div id="div3">
</div>
</div>
</div>
<input type="button" id="btn" value="点击我" />
<script type="text/javascript">
var oDiv3 = document.getElementById('div3');
//console.log(oDiv3.offsetParent);
//console.log(oDiv3.offsetLeft);
</script>
</body>
</html>