分类
默认

absolute 和 relative 定位

  • relative 依据自身定位
  • absolute 依据最近一层的定位元素定位(relative absolute fixed body)
<style>
    .relative {
        position: relative;
        width: 400px;
        height: 200px;
        border: 1px solid #ccc;
        top: 20px;
        left: 50px;
    }
    .absolute {
        position: absolute;
        width: 200px;
        height: 100px;
        border: 1px solid blue;
        top: 20px;
        left: 50px;
    }
</style>
<div>
    <p>absolute 和 relative 定位问题</p>
    <div class="relative">
        <div class="absolute">
            this is absolute
        </div>
    </div>
</div>