css - Flexbox 网格 : How to display 3 items side-by-side but varying vertical positions

标签 css flexbox

红色方框是元素,灰色背景是容器:

IMAGE

我想在一个容器中展示 3 个元素。请查看随附的图片。 使用 flexbox 解决这个问题的最佳方法是什么?在移动 View 上应该是一样的。 谢谢

最佳答案

使用 flexbox,通过 nth-child 来改变 flex 对象的特定高度。

例如:

//HTML
<div class="container">
    <div class="flex"></div>
    <div class="flex"></div>
    <div class="flex"></div>
</div>

//CSS
.container{
  background: #AAA;
  border: 1px solid black;
  display: flex;
  height: 15vw;
  width: 20vw;
  }
.flex{
  background: #F00;
  height: 7vw;
  margin-left: 1.25vw;
  width: 5vw;
  }
.flex:nth-child(1){
  margin-top: 6vw;
  }
.flex:nth-child(2){
  margin-top: 1vw;
  }
.flex:nth-child(3){
  margin-top: 5vw;
  }

请看这里的例子: https://jsfiddle.net/mn8ukbae/7/

关于css - Flexbox 网格 : How to display 3 items side-by-side but varying vertical positions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55876277/

相关文章:

html - 你如何使 anchor 标签居中?

html - 文本溢出 : ellipsis not working

html - 高度百分比不起作用?

css - 在 flex 容器的剩余空间(不是全宽)中水平居中 flex 元素

html - 与 Flexbox 对齐的意外元素

html - 水平滑动照片

html - 仅将边框图像用于底部边框?我们的 CSS 似乎是在整个 div 中复制图像

html - Firefox和Chrome之间的flex-shrink差异

html - iOS中的Flex图像,使图像宽度均匀

html - 为什么 flex 元素不缩小过去的内容大小?