Mdd*_*Mdd 3 html css css-position
我有2个div,position:absolute里面有一个容器position:relative.我试图.box1在隐藏第二个div时显示第一个div .box2,使用绝对定位.
我可以看到容器周围的边框是否已折叠,但我不确定我缺少什么,以便它包裹显示的内部div.
.container {
border: 1px solid black;
position: relative;
height: 100%;
}
.box {
text-align: center;
padding: 1em;
position: absolute;
width: 100%;
}
.box1 {
background-color: #CECECE;
top: 100%;
}
.box2 {
background-color: #87CEEB;
top: 0%;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="box box1">
Content 1
</div>
<div class="box box2">
Content 2
</div>
</div>Run Code Online (Sandbox Code Playgroud)