html - 为什么当我使用 flex-direction 时我的 div 会消失?
问题描述
我目前正在研究我的网页的响应能力,并且已经实现了 flexbox 来定位我的页面元素。我遇到的问题是,当我在媒体查询中使用“flex-direction:column”时,div 在调整浏览器大小时消失。我在这里做错了什么?
#blue {
background-color: #57afb5;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#dark-green {
background-color: #29914c;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#green {
background-color: #91e3ad;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#orange {
background-color: #c98a32;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#top {
display: flex;
justify-content: space-around;
margin-top: 2%;
}
#bottom {
display: flex;
justify-content: space-around;
margin-top: 2%;
}
/* responsive web design*/
@media only screen and (max-width: 960px) {
#top {
display: flex;
flex-direction: column;
}
#bottom {
display: flex;
flex-direction: column;
}
/*end of responsive web design*/
<div class='main-content'>
<div id='Navbar_Link-Toggle' style='font-size: 20px'>
<i id='main' class='fas fa-bars'></i>
</div>
<div class='container'>
<div class='Navbar'>
<a class='links' href=''>FOOD</a>
<a class='links' href=''>FUN</a>
<img id='center-logo' src='img/SAMO.png'>
<a class='links' href=''>HISTORY</a>
<a class='links' href=''>LOCATION</a>
</div>
</div>
<div class='header'>
<img id='food' src='img/food.jpg'>
</div>
</div>
<div id='top'>
<div id='blue'></div>
<div id='dark-green'></div>
</div>
<div id='bottom'>
<div id='green'></div>
<div id='orange'></div>
</div>
</div>
解决方案
#top 和 #bottom div 没有高度。你可以给他们一个高度。IE#top, #bottom { hight: 700px; }
或者,display: block;
如下例所示使用。
旁注:当我缺少元素时,我有时会在它们上扔一个border: solid red 2px;
以更好地可视化正在发生的事情。希望对下次有帮助!
#blue {
background-color: #57afb5;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#dark-green {
background-color: #29914c;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#green {
background-color: #91e3ad;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#orange {
background-color: #c98a32;
max-width: 470px;
height: 350px;
flex: 1;
justify-content: space-around;
}
#top {
display: flex;
justify-content: space-around;
margin-top: 2%;
}
#bottom {
display: flex;
justify-content: space-around;
margin-top: 2%;
}
/* responsive web design*/
@media only screen and (max-width: 960px) {
#top,
#bottom {
display: block;
}
}
/*end of responsive web design*/
<div class='main-content'>
<div id='Navbar_Link-Toggle' style='font-size: 20px'>
<i id='main' class='fas fa-bars'></i>
</div>
<div class='container'>
<div class='Navbar'>
<a class='links' href=''>FOOD</a>
<a class='links' href=''>FUN</a>
<img id='center-logo' src='img/SAMO.png'>
<a class='links' href=''>HISTORY</a>
<a class='links' href=''>LOCATION</a>
</div>
</div>
<div class='header'>
<img id='food' src='img/food.jpg'>
</div>
</div>
<div id='top'>
<div id='blue'></div>
<div id='dark-green'></div>
</div>
<div id='bottom'>
<div id='green'></div>
<div id='orange'></div>
</div>
推荐阅读
- arrays - 检查数组是否使用分治法排序
- php - 将 ACF Post Object 字段添加到 Wordpress 管理列
- r - processR包的modSummary函数返回NULL
- floris - 从 floris v1.1.4 开发分支运行优化示例时出现 ModuleNotFoundError
- mysql - 无法在 aws amazon linux v2 内的 django 视图函数中检索或创建数据库对象
- python - 如何解决“TypeError: max() received an invalid combination of arguments - got (Linear, int), but expected”?
- javascript - 调查流畅快速的 UI,使用 Svelte 3 的疑问
- gatsby - gatsby-plugin-mdx 上标和下标支持
- shell - 如何在 Shell 脚本中将日期格式 MM-DD-YY HH:MI AM/PM 转换为 YYYY-MM-DD
- idyll - 在 Idyll 中使 js 函数可访问的方法?