【问题标题】:How can I put one box next to another with flexbox?如何使用 flexbox 将一个盒子放在另一个盒子旁边?
【发布时间】:2021-07-24 22:44:57
【问题描述】:

我正在尝试使用 flexbox 将两个 flex 容器彼此相邻放置,以此布局为参考(我希望它像这里的第一行一样,左侧的部分图像在一个盒子内,另一个一个在右边)

这是我目前针对这两个容器的代码:

.chaco-container {
  border: $borde-textos;
  background-color: #bda89c;
  margin: 0;
  padding: 1em;
  width: 50%;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.plan-container {
  background-color: white;
  border: $borde-textos;
  width: 50%;
  display: inline-flex;
}

【问题讨论】:

    标签: css layout flexbox position


    【解决方案1】:

    display: flex; 需要应用在父容器上。查看以下示例 sn-p。

    .flex-container {
      display: flex;
    }
    
    .chaco-container {
      width: 50%;
      background-color: yellow;
    }
    
    .plan-container {
      width: 50%;
      background-color: skyblue;
    }
    <div class="flex-container">
      <div class="chaco-container">...content</div>
      <div class="plan-container">...content</div>
    </div>

    【讨论】:

      【解决方案2】:

      我认为您可能会面临两个内联 flex 元素之间的间隙,这会导致第二个元素进入下一行。

      解决这个问题:

      1. 将此用作重置:

        *{ margin: 0; padding: 0; box-sizing:border-box; }

      2)给计划(第二个)容器负边距:

      margin-left:-4px;
      

      (增加负像素数,直到两个flexbox在同一行)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-04
        • 2016-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-19
        • 1970-01-01
        • 2017-09-23
        相关资源
        最近更新 更多