HTML子元素遮盖父元素

Posted on Posted in Misc

父元素relative定位,然后子元素absolute定位,指定top,left,bottom,right设置为0

#parent {
    position: relative;
    height: 100px;
    width: 100px;
}

#child {
    position: absolute;
    top:0;
    left: 0;
    right: 0;
    bottom: 0;
}

无需指定z-index

===
[erq]

Leave a Reply

Your email address will not be published. Required fields are marked *