子绝父相布局经常使用,是一种比较经典的定位布局

  •  父盒子使用相对定位:占位置,不会对下面的同级盒子产生影响;基准点,子盒子以父盒子左上角为基准点进行移动 
  • 子盒子使用绝对定位:不占位置,完全脱标,不会对兄弟元素产生影响
<body>
    <div class="father">
        <div class="son"></div>
    </div>
</body>
<style>
        .father{
            width: 300px;
            height: 300px;
            border: 1px solid #000;
            position: relative;
        }
        .son{
            width: 100px;
            height: 100px;
            background: rgb(189, 17, 17);
            position: absolute;
            left: 100px;
            bottom: 100px;
        }
    </style>

子绝父相布局

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2020-01-19
  • 2022-12-23
  • 2021-09-19
  • 2021-10-14
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2021-09-19
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2018-12-17
相关资源
相似解决方案