<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .box1 {
            width: 300px;
            height: 300px;
            padding: 100px;
            margin: 100px;
            position: relative;
            border: 100px solid #000;
            background-color: pink;
        }
        .box2 {
            width: 100px;
            height: 100px;
            background-color: red;
            /*position: absolute;*/
            /*left: 10px;*/
            /*top: 10px;*/
        }
    </style>
</head>
<body>
<div class="box1">
    <div class="box3">
        <div class="box2" style="left: 10px"></div>
    </div>
</div>

<script>

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

    //offsetTop和offsetLeft
    console.log(box2.offsetLeft);
    console.log(box2.style.left);



</script>

</body>
</html>

  

相关文章:

  • 2022-12-23
  • 2022-01-26
  • 2021-07-25
  • 2022-12-23
  • 2022-01-03
  • 2021-08-19
  • 2021-11-23
猜你喜欢
  • 2021-06-26
  • 2022-12-23
  • 2021-09-17
  • 2021-12-19
  • 2021-12-15
相关资源
相似解决方案