css - CSS Flexbox - 第一个孩子的高度相等
问题描述
我想要实现的是当布局分解为移动时,图像块与标题/内容块的高度匹配。
布局非常棘手,它在桌面视图上按预期工作,标题栏位于顶部全宽。我认为问题是在移动视图上使用 flex-wrap: wrap?(我已经让这个布局使用 CSS 网格工作,但不幸的是它不能用于生产)
.wrapper {
display: flex;
flex-wrap: wrap;
width: 100%;
justify-content: flex-end;
}
.title {
background: tomato;
width: 50%;
}
.image {
background: cornflowerblue;
width: 50%;
height: 150px;
}
.content {
background: gold;
width: 50%;
}
<div class="wrapper">
<div class="image">img</div>
<div class="title">title</div>
<div class="content">content</div>
</div>
解决方案
使用此代码
.wrapper {
display: flex;
flex-wrap: wrap;
width: 100%;
justify-content: flex-end;
}
.title,
.image,
.content {
width: 50%;
}
.title {
background: tomato;
}
.image {
background: cornflowerblue;
}
.content {
background: gold;
}
@media only screen and (min-width: 800px) {
.title {
width: 100%;
order: 1;
}
.image {
order: 2;
height: 150px;
}
.content {
order: 3;
}
}
推荐阅读
- matlab - 在 Matlab 中检索文本文件内容信息
- java - CentOS OpenJDK 软件包是否通过了 TCK 合规性测试?
- jquery - 为什么 $.get 不加载另一个文件夹中的 php 文件,而是错误 500
- javascript - 异步挫折:我应该使用回调以及如何通过多个模块传递它们?
- delphi - 在 Delphi Community Edition 中保存桌面布局
- selenium - 页面对象模型模式的设计关注点
- java - IntelliJ 评估中 SOAP 的 RequestContext 上的 SOAPFaultException
- php - Yii2 下拉列表和数组助手“调用数组上的成员函数 isAttributeRequired()”
- php - 美国允许州通过 Woocommerce 自定义设置页面
- sql - 显示一个具有多个值的列的值