html - flex 网格 : Alternate left and right

标签 html css flexbox

使用 Flexbox:我想将一系列 div 垂直放置在一个包含 div 的下方,一些在左边,一些在右边。其中每个 div L & R 是容器 div 宽度的 70%。 L div 必须固定在容器的左侧,R div 必须固定在容器的右侧。

L
      R
L
L
      R
      R
      R
L

最佳答案

制作一个具有 flex-direction: column 的 flex 容器,然后根据其类与 align-self 对齐每个子项:

* {
  box-sizing: border-box;
}

.column {
  display: flex;
  flex-direction: column;
  width: 100%;
}

div.left, div.right {
  width: 70%;
  padding: 5px 10px;
}

div.left {
  align-self: flex-start;
  background: orange;
}

div.right {
  align-self: flex-end;
  background: yellow;
  text-align: right;
}
<div class="column">
  <div class="left">L</div>
  <div class="right">R</div>
  <div class="left">L</div>
  <div class="right">R</div>
  <div class="left">L</div>
  <div class="left">L</div>
  <div class="right">R</div>
  <div class="right">R</div>
  <div class="right">R</div>
  <div class="left">L</div>
</div>

关于html - flex 网格 : Alternate left and right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44760179/

相关文章:

html - 如何将图像作为 [object HTMLImageElement] 放入 div 中

javascript - 与 div 后面的元素交互

css - IE11 - Flex 子项占据全高

html - CSS flex-item align self 不适用于 flex-wrap parent

html - 如何在嵌入式 swf 上隐藏边框

html - 表格顶部的页脚位置

html - 四个 Div 彼此在 Safari 中未正确显示

html - 为什么这种垂直对齐不适用于 Bootstrap ?

javascript - 如何使用 javascript 处理此布局?

javascript - flex 元素是否有可能与它们上方的元素紧密对齐?