我试图将这些元素堆叠起来,使它们彼此重叠,但它们最终会水平挤压。我做错什么了?
HTML格式:
.content-wrapper {
position: absolute;
top: 0;
left: 0;
height:100%;
width:100%;
display: flex;
align-items: center;
justify-content: center;
}
.content-box {
background-color: #f2f2f2;
padding: 5vh 5vw;
font-family: "Roboto";
color: #676767;
text-align: center;
max-width: 60vw;
position: relative;
z-index:10;
margin: 1vh
}
<div class="content-wrapper">
<div class="content-box">
<span class="title"> Stats </span>
<br>
<div class="sep"></div>
<p> Lorem ipsum 1 </p>
</div>
<div class="content-box">
<span class="title"> Stats </span>
<br>
<div class="sep"></div>
<p> Lorem ipsum 2 </p>
</div>
</div>
最佳答案
使用弹性框代替。flex direction
.box-list {
padding: 10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.box {
flex: 0 0 auto;
width: 50px;
height: 50px;
background-color: #ccc;
margin-bottom: 10px;
}
<section class="box-list">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</section>
关于html - 相对定位的内容没有垂直堆叠?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44373188/