html - 我怎样才能并排放置两个div,第三个div与第二个对齐

标签 html css

我有两个并排的 div(div1 和 div2),我想在 div2 下放置第三个 div (div3)。

我已经尝试向 div3 添加边距以尝试将其对齐,但 div1 宽度是动态的。我也尝试过将 div3 向右浮动,但是内容太远并且没有像上图那样与 div2 的开头对齐

.row {
  display: flex;
}

.div1 {
  margin-right: 1em;
}
<div class="row">

  <div class="div1">
    <p> some content with unknown width</p>
  </div>

  <div class="div2">
    <p> some content </p>
  </div>

</div>

<div class="div3">
  <p> some content that should be under div2 </p>
</div>

默认行为是 div3 在 div1 之下。我试图将 div3 放在 div 2 下面

最佳答案

您可以通过以下方式做到这一点:

    .wrapper {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
    }
    
    .div {
      flex-basis: 50%;
      min-height: 100px;
    }
    
    .div1 {
      background: red;
    }
    .div2 {
      background: blue;
    }
    .div3 {
      background: aqua;
    }
<div class="wrapper">
  <div class="div div1">div1</div>
  <div class="div div2">div2</div>
  <div class="div div3">div3</div>
</div>

这是一个 codepan

关于html - 我怎样才能并排放置两个div,第三个div与第二个对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58153825/

相关文章:

html - 将 Canvas 和 SVG 设置为具有流动的宽度和高度

javascript - 限制foreach循环 knockout

php - 如何突出显示搜索结果

javascript - 将 SVG 转换为 PNG,并将应用图像作为 svg 元素的背景

html - 媒体查询,通过类更改特定的 TD 标签字体大小

javascript - 将下拉列表框转换为 UL LI?

html - 使用边距和/或填充强制元素到位是否被认为是不好的做法?

java - 推荐的 PDF 到 HTML API/工具

html - 如何确定 float 元素影响非 float 元素高度的原因(D7 views blocks with zen theme)?

html - CSS 固定菜单——如何不在容器外运行?