Css每天一个小技巧,绝对定位子元素尽然能撑起父元素高度

89 阅读1分钟

今天偶然发现 绝对定位子元素撑起了父元素的滚动高度,觉得很奇怪

上代码 ``


```<style>
    .fathserDiv{
      width: 100px;
      height: 100px;
      position: relative;
      background-color: red;
    }
    .child{
      position: absolute;
      height: 300px;
      width: 200px;
      background-color: blue;
    }
  </style>
</head>
<body>
  <div class="fathserDiv">
    <div class="child">

    </div>
  </div>
</body>
```