javascript - 带有粘性页脚的页面中的垂直居中 div
问题描述
我正在尝试垂直对齐 IE11 中的 div。我试图在这里使用@billbad 的答案
我的 axample 与 Internet 上的许多其他示例之间的区别在于它们不使用粘性页脚,我认为这就是导致我出错的原因。
HTML
<div class="wrapper">
<div class="art-header"></div>
<div class="outer-container">
<div class="middle-container text-center">
<div class="contner">
<button type="button" class="btn btn-primary text-center" (click)="addLine()">Primary</button>
<ul>
<li *ngFor="let line of name" >
{{ line }}
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="rmpm-footer">
<p>Footer</p>
</div>
</div>
CSS的一部分
.contner {
min-height: 242px;
max-height: 100%;
width: 604px;
padding-top:10px;
background-color: #FFFFFF;
box-shadow: 0 1px 1px 1px rgba(0,0,0,0.1);
padding-bottom: 12px;
transition: max-height .4s;
-webkit-transition: .4s;
position: relative;
margin-left: auto;
margin-right: auto;
margin-top: 40px;
}
.middle-container {
display: table-cell;
vertical-align: middle;
}
.outer-container {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
实际上 div 没有很好地居中并且页脚高度已调整大小。那不是我要找的。
预期的行为是当我添加行时 div 仍然居中,然后当 div 大于初始页面高度时页脚下降。
我创建了一个stackblitz 示例,您可以在那里直接检查我的代码。
解决方案
尝试margin-top
改用display: table-cell
.middle-container {
margin-top: 40%;
}
推荐阅读
- python - 使用 discord.py 将 mp3 播放到语音频道
- c# - 如何自动更新 WPF DataGrid 和 xml 之间的绑定
- javascript - 通过匹配选定的列来合并两个多维数组,并返回一个包含所有行和列的新数组
- excel - 打开或选择 Excel 并执行宏
- python-3.x - 在wsl2 ubuntu 20.04上尝试(pyenv install -v 3.9.0)时pyenv BUILD FAILED
- laravel - 在您的集群、Laravel、docker 中找不到活动节点
- python - Python - 解析 YAML 字典以按层次结构获取密钥
- reactjs - 无法将反应应用程序部署到 github 页面 404 错误
- python - 如何在python中使用两个不同的数据框?
- assembly - 为什么 push DWORD 指令等于 8 个字节?