首页 > 代码库 > 03-offsetParent属性

03-offsetParent属性

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div class="box1" style="position: absolute;">
        <div class="box2" style="position: fixed;">
            <div class="box3"></div>
        </div>
    </div>

<script>
    //offsetParent:复习盒子中带有定位的盒子
    //复习盒子中都没有定位,返回body
    //如果有,谁有返回最近哪个

    var box3 = document.getElementsByClassName("box3")[0];

    console.log(box3.offsetParent);

</script>

</body>
</html>

  

03-offsetParent属性