html - Flexbox:到达页面底部时如何将项目包装在 flexbox 内?
问题描述
我正在处理自定义起始页。我的目标是在一个弹性框中有几列彼此相邻。列本身也是 flexbox 并用圆圈填充,这些圆圈稍后将成为链接。
我想要实现的是将起始页的最大高度限制为可见屏幕区域,并在列到达页面底部时让列内的圆圈环绕到列的顶部。
这在我为列设置固定高度(例如 900 像素)时有效。但是,当我设置相对高度时,项目不会换行而是溢出页面底部并出现滚动条。
如何调整我的代码,使内容仅限于可见屏幕区域?
我对 html 很陌生,这是我的第一个真正的项目,所以我的代码在某些地方可能看起来有点奇怪。
这是我的 html 标记:
<body>
<div class="wrapper">
<div id="row1" class="fixedflex">This is the header</div>
<div id="row2" class="flexflex">
<div class="tilebox">
<div class="tilecolumn">
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
</div>
<div class="tilecolumn">
<div class="tile"></div>
</div>
<div class="tilecolumn">
<div class="tile"></div>
</div>
</div>
</div>
<footer id="row3" class="fixedflex">Footer</footer>
</div>
</body>
这是css样式表的一部分
.wrapper {
/*
border-style: solid;
border-color: green;
border-width: 1px;
*/
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.fixedflex {
display: flex;
flex-direction: column;
flex-grow: 0;
flex-shrink: 0;
width: 100%;
border-style: solid;
border-color: white;
border-width: 1px;
}
.flexflex {
display: flex;
justify-content: center;
align-items: flex-start;
align-content: flex-start;
flex: 2;
border-style: solid;
border-color: yellow;
border-width: 1px;
}
.tilebox {
border-style: solid;
border-color: red;
border-width:5px;
width: 80%;
height: 100%;
display: flex;
flex-wrap: nowrap;
flex-direction: row;
justify-content: center;
align-items: flex-start;
align-content: flex-start;
flex-grow: 0;
flex-shrink: 0;
}
.tilecolumn {
display: flex;
flex-direction: column;
max-height: 100%;
justify-content: flex-start;
align-items: center;
align-content: center;
flex-wrap: wrap;
flex-basis: 20%;
flex-grow: 2;
flex-shrink: 2;
margin: 20px;
}
.tile {
display: flex;
margin: 10px;
width: 100px;
height: 100px;
color: var(--text_color);
text-decoration: none;
align-items: center;
text-align: center;
justify-content: center;
border-radius: 50%;
background: var(--light_background);
}
我也在使用 normalize.css,但我认为那里没有任何东西会导致我的问题。
解决方案
我首先将高度固定fixedflex
为 20px,所以高度flexflex
应该是 100vh - 两者的高度fixedflex
和边框,所以它将是: height: calc(100vh - 72px);
: stackblitz : https://stackblitz.com/edit/angular-tfpckr
HTML:
<body>
<div class="wrapper">
<div id="row1" class="fixedflex">This is the header</div>
<div id="row2" class="flexflex">
<div class="tilebox">
<div class="tilecolumn">
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
</div>
<div class="tilecolumn">
<div class="tile"></div>
</div>
<div class="tilecolumn">
<div class="tile"></div>
</div>
</div>
</div>
<footer id="row3" class="fixedflex">Footer</footer>
</div>
</body>
CSS:
.wrapper {
/*
border-style: solid;
border-color: green;
border-width: 1px;
*/
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.fixedflex {
display: flex;
flex-direction: column;
height: 20px;
flex-grow: 0;
flex-shrink: 0;
width: 100%;
border-style: solid;
border-color: white;
border-width: 1px;
}
.flexflex {
display: flex;
justify-content: center;
align-items: flex-start;
align-content: flex-start;
height: calc(100vh - 72px);
flex: 1;
border-style: solid;
border-color: yellow;
border-width: 1px;
}
.tilebox {
border-style: solid;
border-color: red;
border-width:5px;
width: 80%;
height: 100%;
display: flex;
flex-wrap: nowrap;
flex-direction: row;
justify-content: center;
align-items: flex-start;
align-content: flex-start;
flex-grow: 0;
flex-shrink: 0;
}
.tilecolumn {
display: flex;
flex-direction: column;
max-height: 100%;
justify-content: flex-start;
align-items: center;
align-content: center;
flex-wrap: wrap;
flex-basis: 20%;
flex-grow: 2;
flex-shrink: 2;
margin: 20px;
}
.tile {
display: flex;
margin: 10px;
width: 100px;
height: 100px;
color: var(--text_color);
text-decoration: none;
align-items: center;
text-align: center;
justify-content: center;
border-radius: 50%;
background: var(--light_background);
}
推荐阅读
- java - 从 DStream 中提取触发处理的文件名
- sql - 如何在使用 sql 或 pl/sql 从两个表中检索值时添加动态列?
- c# - 为 c# windows 窗体应用程序实现语言文件
- mysql - 如何获取列值连接相同的表值
- typescript - Vscode API:当“案例”显示贡献时
- typescript - 订阅不适用于角度 6 中的可观察对象
- sql - 一张表上有很多外键 - 性能问题
- javascript - 如何解决有关本机反应的依赖性问题
- winusb - 我可以在没有 GUID 的情况下使用 Windows WinUSB 吗?
- java - 单元测试期间出现 NullPointerException