【发布时间】:2020-04-04 15:22:52
【问题描述】:
在我的 Angular 应用程序中,我很难让页脚粘在页面底部。我尝试了许多不同的事情,但似乎无法弄清楚我做错了什么。我已经定义了容器 div 的高度,所以我知道视口大小,因此页脚应该能够识别视口的底部并留在那里。然而,随着内容的增长,页脚不会随着内容的增长而增长。
HTML:
<body style="margin:0; padding:0; height:100%;">
<app-root></app-root>
</body>
应用程序根 html:
<div class="container">
<app-header id="header"></app-header>
<div id="body">
<router-outlet></router-outlet>
</div>
<app-footer id="footer"></app-footer>
</div>
CSS:
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
height:100%;
position:relative;
}
#header {
padding-bottom:10px;
}
#body {
padding:10px;
padding-bottom:10px;
}
#footer {
position: absolute;
bottom:0;
width:100%;
height:60px;
}
【问题讨论】:
-
为什么不尝试使用flex approach(您的 html 是否也出现在您的 body 标签内,或者实际上是这样吗?)
-
我尝试了 flexbox 方法,但没有运气。是的,它是一个基于 Angular 的应用程序,“app-root”是您看到的第二个 html 块
-
尝试位置:改为固定
-
我不想固定页脚我希望它是粘性的