html - 粘性页脚不适用于 Angular 5

标签 html css angular

这是我的 Angular 元素:

https://stackblitz.com/edit/angular-1g7bvn

我试过从 this example 获取粘性页脚无功而返:

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 标记。如果您使用 :host 选择器将 body 中的样式添加到您的 app.component.css - 它会工作得很好。

:host {
  display: flex;
  flex-direction: column;
  height: 100%;    
  margin: 0;
}

这是一个 stackblitzz例子

关于html - 粘性页脚不适用于 Angular 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54952346/

相关文章:

javascript - ng-click事件不适用于angular js中的链接

html - 无论屏幕大小如何,容器周围的图像都会跟随容器

html - 使用 'top' css 属性防止文本进入图像

php - 设计比赛支架 - 不能很好地组合在一起

javascript - 将 css 样式规则作为 Javascript 函数中的参数的正确方法是什么?

javascript - 如何使 CSS Accordion 在从一个部分转到另一个部分时自动关闭打开的内容

javascript - Angular 2中路线更改时的结束间隔

javascript - 错误语法错误 : Unexpected token < in JSON at position 0

javascript - Angular 7 : How to eval an arithmetic string

javascript - 在 &lt;iframe/> 上设置沙箱 ="allow-scripts allow-popups allow-same-origin"是否安全?