html - 相对定位的内容不垂直堆叠?

标签 html css flexbox

我试图堆叠这些元素,使它们彼此重叠,但它们最终水平挤压。我做错了什么?

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 盒子。 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/

相关文章:

html - Bootstrap 导航栏总是折叠的

css - 在Angular 7中使用PrimeNG的flexgrid没有任何效果

html - 如何在 Chrome 中禁用谷歌从 HTML 翻译

javascript - 在下拉菜单上应用链接但下拉菜单在移动设备上不起作用

html - 使一列单元格确定行高

css - 如何在 CSS 中实现最大 50% 的高度?

html - 折叠 Flexbox 之谜

html - RegEx 仅返回 'href' 标签的 'link' 属性?

html - 使内容占据整个屏幕宽度

html - 如何使用 flexbox 将 2 行图像放入 'column'