使用绝对定位
如果你想要子元素完全撑满父元素的高度,可以使用绝对定位。这种方法适用于当子元素需要完全覆盖父元素时。
<div class="parent"><div class="child"><!-- 子类内容 --></div>
</div>
.parent {position: relative; /* 父元素需要是相对定位 */height: 100%; /* 或者具体高度,根据需要设置 */
}.child {position: absolute;top: 0;bottom: 0; /* 从顶部到底部完全填充 */width: 100%; /* 宽度也设置为100%以确保完全覆盖 */
}