html - 粘性页脚不适用于 Angular 5
问题描述
这是我的 Angular 项目:
https://stackblitz.com/edit/angular-1g7bvn
我已经尝试从这个示例中获取粘性页脚,但无济于事:
html {
height: 100%;
font-family: sans-serif;
text-align: center;
}
body {
display: flex;
flex-direction: column;
height: 100%;
margin: 0;
}
header{
flex-shrink: 0;
background: yellowgreen;
}
.content {
flex: 1 0 auto;
background: papayawhip;
}
footer{
flex-shrink: 0;
background: gray;
}
一定有什么小东西我做错了,但我看不到。
解决方案
Angular 将您的组件呈现为标签,因此在您的情况下,my-app
组件是 DOM 树上的实际标签。
<body>
<my-app>
<header></header>
<section></section>
<footer></footer>
</my-app>
</body>
并且您的所有样式都应用于body
标签。如果您使用选择器添加到您app.component.css
的样式中- 它会工作得很好。body
:host
:host {
display: flex;
flex-direction: column;
height: 100%;
margin: 0;
}
这是一个stackblitzz示例
推荐阅读
- java - 重复的键值违反了唯一约束,但它不应该 [Spring Boot,PostgreSQL]
- python - 如何在不使用 python 中的类的情况下实现数据结构?
- android - Firebase 身份验证所需的 Android 权限
- tensor - 张量和张量等级(CP等级)
- javascript - CORS 策略已阻止从源“null”访问音频:请求的资源上不存在“Access-Control-Allow-Origin”标头
- php - 如何通过发布请求检查我在 laravel 控制器上是否有正确的文件
- excel - 仅删除数字重复行?
- .net-core - 在 Blazor 中,是否有更好的方法从列表中添加元素?
- javascript - 我想将过渡添加到我的商店的粘性标题
- c - 如何在二进制无符号字符上使用 zpipe 膨胀