html - Angular 2底部的粘性页脚

标签 html css angularjs

我正在 Angular 2 中构建一个元素,我需要一个必须始终位于页面底部的粘性页脚,而不是固定的。示例:http://codepen.io/chriscoyier/pen/uwJjr

'app'组件的结构是这样的:

<header-main></header-main>
<router-outlet></router-outlet>
<footer>...</footer>

问题可能与 Angular 本身无关,而仅与 CSS 有关。但是,我尝试这样实现它:

app {
   min-height: 100%;
   position: relative;
}

footer {
   position: absolute;
   bottom: 0;
   left: 0;
   width: 100%;
   height: 271px;
}

结果很糟糕: enter image description here

有趣的是,如果我在检查器中关闭页脚位置,然后再次打开,页脚就可以了: enter image description here

解决方案:

app {
  min-height: 100%;
  width: 100%;
  margin-bottom: -271px;
  display: table;
}

header-main,
router-outlet,
footer{
  display: table-row;
}

header-main {
 height: 60px;
}

router-outlet {
  position: absolute;
}

footer {
  height: 271px;
}

最佳答案

这是我解决粘性页脚的方法(未修复)

app.component.ts
.....
export class AppComponent {  
   clientHeight: number;

 constructor() {
    this.clientHeight = window.innerHeight; 
 }
 }

app.component.html

<div [ngStyle]="{'min-height': clientHeight + 'px', 'margin-bottom': '-200px'}"> 
          <!-- 'margin-bootom': '-FooterHeight' -->
    <app-navbar></app-navbar> 
          <!-- Your Navbar here -->
    <router-outlet></router-outlet>
    <div style="height: 200px"></div> 
          <!-- 200px is FooterHeight  this will push 
          the footer so it will not overlap if you have very long content  -->
</div>

<app-footer></app-footer> 
<!-- Your footer here -->

关于html - Angular 2底部的粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35355652/

相关文章:

javascript - 查询。使用延迟将 css 应用于具有类的每个元素

javascript - 使用 d3 动画 ng-repeat 指令模板的问题

html - 如何在组件 View 中访问根作用域

javascript - jquery克隆方法在页面内克隆多个(多个)div(不是单个div多次)

html - 带有图标的纯 CSS 可折叠列表

html - 页脚与内容 div 重叠

javascript - 在主页中的文本上弹出图像

angularjs - TypeError : angular. element.cleanData 不是函数

css - 获取div angular js的高度

javascript - kinetic.js 绝对线位置而不是相对位置