css - Flexbox 有问题 2 列 3 项
问题描述
我试图让我的 flexbox 项目正确包装,但似乎无法让它按照我需要的方式工作。我有部分(紫色、粉色、蓝色),粉色和蓝色的高度可能不同,因此很难为容器设置正确的高度。粉色一般高度较短,而蓝色一般较长但可以较短。粉红色永远不会像紫色那样高。桌面上的布局,这不是我想要的,目前看起来像这样:
我希望桌面看起来像这样:
移动布局正确,如下所示:
我的代码目前是
#container { display: flex;flex-wrap: wrap;}
#purple {flex: 0 0 25%; max-width: 25%; width: 25%}
#pink { flex: 0 0 75%; max-width: 75%;width: 75%}
#blue { flex: 0 0 75%; max-width: 75%;width: 75%}
<div id="container">
<section id="purple"><img /></section>
<section id="pink"><p>small content block</p></section>
<section id="blue"><p>large content block</p></section>
</div>
解决方案
I see your expected view works for mobile view and You can use media-query for desktop view,
For Desktop view, you need to flow you container in column direction and apply max-height to wrap items of container.
@media only screen and (min-width: 768px){ #container { display: flex; flex-flow:column wrap; max-height:100vh; } #purple{ height: 100vh; margin-right:15px; } }
推荐阅读
- c - 读取 GPIOB_IDR 寄存器时值不正确
- java - 如何将我的 BaseAdapter 转换为 RecyclerAdapter
- javascript - 使用把手在 .hbs 文件之间进行链接的最简单方法是什么?
- javascript - 在 Chrome 扩展中将变量从 popup.js 发送到 background.js
- c++ - ServerSocket 抛出 InvalidArgumentException,但文档没有说明原因。为什么?
- javascript - 重新索引由另一个数组索引的数组,其中元素从两者中删除
- android - 如何使 RadioButtons 在 Android 上的旅游指南中为我生成一些位置
- javascript - 来自 Ajax GET 的 HTML 中的角度显示响应
- c++ - 按项目数据从 QStandardItemModel 中查找/删除一行
- python-3.x - 使用带有单轴的 seaborn 的 catplot,但仍指定色调