[英]Angular 2 + Material 2 : Sticky Footer with a md-toolbar
I actually try to make a sticky footer within an angular2/Material2 app, from a md-toolbar component. 我实际上尝试在md-toolbar组件的angular2 / Material2应用程序中制作粘性页脚。
Maybe this is just not an appropriate element, but this would be nice to make it this way since it would fit the app style with no additionnal code. 也许这不是一个合适的元素,但这样做会很好,因为它适合app风格,没有额外的代码。
I am using Angular 2 (CLI), Material2 ( https://github.com/angular/material2 ) and Flex Layout ( https://github.com/angular/flex-layout ) 我正在使用Angular 2(CLI),Material2( https://github.com/angular/material2 )和Flex Layout( https://github.com/angular/flex-layout )
Here is a sample code of what the app looks like : 以下是应用程序外观的示例代码:
<md-sidenav-container class="sd-layout">
<md-sidenav #sidenav class="app-sidenav" mode="push">
//My links in the sidenav
</md-sidenav>
<md-toolbar color="primary">
//Here is the "REAL" toolbar, on top of page, with app name, and so on
</md-toolbar>
<router-outlet>
//Here is the application display, routing, navigation, security, all the magic happens here
</router-outlet>
<my-footer>
//Here is the custom footer I tried to make...
</my-footer>
</md-sidenav-container>
So, basically, nothing weird in this code... Now, the footer template item : 所以,基本上,在这段代码中没有什么奇怪的...现在,页脚模板项:
<md-toolbar class="footer">
//Here is my footer
</md-toolbar>
CSS "footer" Class holds this : CSS“footer”类认为:
.footer {
position:relative;
right:0;
left:0;
bottom:0;
}
Once again, nothing magic... At this point, the footer appears directly under the router-outlet. 再一次,没什么魔力......此时,页脚直接出现在路由器插座下面。 Nice, but not enough : if the router-outlet is empty or not tall enough to fit the page (device height), then it leaves an empty space under it, so we got this kind of display :
很好,但还不够:如果路由器插座是空的或不够高,不适合页面(设备高度),那么它下面留下一个空的空间,所以我们得到了这种显示:
What I'd like to get as result : 我想得到的结果是:
Thanks for reading / help 感谢您的阅读/帮助
You can use this: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 你可以使用这个: https : //philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/
<div class="maindiv">
<md-toolbar>your toolbar</md-toolbar>
<md-sidenav-container>your menu</md-sidenav-container>
<div class="site">
<div class="content">
<router-outlet></router-outlet>
</div>
<footer>
<p>footer</p>
</footer>
</div>
</div>
end css: 结束css:
.maindiv {
min-height: 100vh;
}
.site{
display: flex;
flex-direction: column;
min-height: 94vh;
}
.content{
flex: 1;
}
In order to set the footer always at bottom you can try the below code 为了将页脚始终设置在底部,您可以尝试以下代码
<mat-sidenav-container class="container">
<mat-sidenav mode="side" opened>Sidenav content</mat-sidenav>
<mat-sidenav-content>
<div fxLayout="column" style="height:100vh;">
<div fxFlex>content goes here</div>
<div fxFlex="50px" fxLayoutAlign="center center" class="footer">footer</div>
</div>
</mat-sidenav-content>
Here i have created a demo using Angular Material anf Flexlayout 在这里,我使用Angular Material和Flexlayout创建了一个演示
https://github.com/Ravi-Rajpurohit/mat-sideNav-stickyFooter https://github.com/Ravi-Rajpurohit/mat-sideNav-stickyFooter
and have a look at my git repo 并看看我的git repo
https://github.com/Ravi-Rajpurohit/mat-sideNav-stickyFooter https://github.com/Ravi-Rajpurohit/mat-sideNav-stickyFooter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.