html - 如何让底部的两个盒子以移动尺寸相互堆叠?
问题描述
我尝试使用不同的 flex 属性,包括 flex-grow/shrink/basis/wrap 和媒体查询,但是当屏幕变小(例如:678px)时我无法堆叠下面的最后一个框,我不确定我是什么我做错了。我只想使用 flexbox 而不是 grid、float 等来完成这个。我正在尝试完全了解如何使用 flexbox,因此非常感谢任何帮助。
HTML
<div class="container">
<div class="container-top"></div>
<div class="container-bottom">
<div class="inner-container subscription">
<div class="inner-container reasons">
</div>
CSS
body {
box-sizing: border-box;
font-family: 'Karla', sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #e6eff6;
position: relative;
}
.container {
display: flex;
flex-direction: column;
/* flex-basis refers to height here since body's (parent) flex-direction is column. */
flex: 0 0 430px;
max-width: 600px;
box-shadow: 0 2px 10px #c3ced6;
border-radius: 6px;
overflow: hidden;
margin: 2rem;
}
.container-top {
height: 40%;
background-color: #fff;
padding: 2rem 2rem 0;
display: flex;
flex-direction: column;
}
.container-bottom {
display: flex;
height: 60%;
/* flex-wrap: wrap; */
}
.inner-container {
padding: 2rem 2.5rem;
}
.inner-container.subscription {
background-color: #2bb3b1;
flex: 1;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.inner-container.reasons {
background-color: #4abebd;
flex: 1;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
解决方案
删除此查询
@media (max-width: 680px) {
.container {
flex-direction:row;
}
}
删除display:flex
_ container-bottom
.container-bottom {
height: 60%;
}
添加1
到弹性值
.container {
display: flex;
flex-direction: column;
flex: 1 0 430px; #adding 1 to flex
max-width: 600px;
box-shadow: 0 2px 10px #c3ced6;
border-radius: 6px;
overflow: hidden;
margin: 2rem;
}
或删除flex
并添加height
到容器
.container {
display: flex;
flex-direction: column;
height : 600px;
max-width: 600px;
box-shadow: 0 2px 10px #c3ced6;
border-radius: 6px;
overflow: hidden;
margin: 2rem;
}
两者都会导致
推荐阅读
- java - 使用java在word文档中添加图像时无法读取输入文件
- python - 在条件中询问密钥是否存在以及在 python 中是否为真
- android - 如何在firebase实时数据库中删除child的特定孩子?
- node.js - 在 Angular NativeScript 中哪里可以找到 app.js 文件?
- php - -> 这在 php 中是什么意思?$blabla->blabla
- python - 如何从 pycharm python 脚本运行“pip install”?
- android - 在 ConstraintLayout 中滚动 RecyclerView 时如何折叠工具栏?
- python - 有没有办法让 os.system 的命令提示符根本不显示
- scala - 在 Spark 中处理文本时使用 \u00c3 记录分隔符问题
- go - Prometheus 计数器:如何使用 golang 客户端获取当前值?