html - flex-wrap 没有包裹在容器内
问题描述
对 css 和 html 非常陌生,并且正在学习 udemy 课程,尽管我已经按照讲师的代码进行了 tee,但我的 flex-wrap 并没有包裹在容器内。这是我到目前为止所拥有的:
body {
font-family: 'Open Sans', sans-serif;
}
h1 {
text-align: center;
}
#container {
background-color: #003049;
width: 90%;
height: 500px;
margin: 0 auto;
border: 5px solid #003049;
display: flex;
flex-direction: row;
justify-content: flex-start;
flex-wrap: wrap;
}
#container div {
width: 600px;
height: 200px;
text-align: center;
}
<h1>Let's Play With Flexbox</h1>
<section id="container">
<div style="background-color: #80ffdb"></div>
<div style="background-color: #64dfdf"></div>
<div style="background-color: #48bfe3"></div>
<div style="background-color: #5390d9"></div>
<div style="background-color: #6930c3"></div>
</section>
当我将它设置为 flex-wrap: nowrap; 它似乎很好,并且保持在#container 内。但是当我把它改成 flex-wrap: wrap; 或 flex-wrap: 换行;彩色 div 框在#container 之外。有什么帮助吗?
解决方案
你的#container
div 有一个固定的高度,500px
浏览器会尊重它并且不会破坏。将其设置为height: 100%
将允许容器根据需要更改高度。
#container {
background-color: #003049;
width: 90%;
height: 100%;
margin: 0 auto;
border: 5px solid #003049;
display: flex;
flex-direction: row;
justify-content: flex-start;
flex-wrap: wrap;
}
推荐阅读
- opengl - 直接将输入纹理复制到输出会在 OpenGL 中产生意想不到的结果
- html - 如果未指定 DIV 的宽度,是否始终默认为 100%?
- java - oracle java官方文档中处理器的吞吐量是多少?
- node.js - 从 dev env 将 React 应用程序部署到 Heroku 后,Fetch 请求中断 - 所有 GET 请求都返回 index.html - 其他是 404
- python - image.size 没有给出正确的图像尺寸
- node.js - 在 Bot Framework 中,我应该使用什么唯一 ID 来保存会话?
- c - 如何使用 SWIG/Python 访问仅具有指针 typedef 的结构的值
- r - 如何创建具有 1 个自变量和 3 个因变量的计数和百分比表和折线图
- bash - 为什么交互式 shell 的子 shell 作为交互式 shell 运行?
- firebase - 在 Firebase 函数中重用通配符值