css footer not displaying at the bottom of the page
https://stackoverflow.com/questions/15960290/css-footer-not-displaying-at-the-bottom-of-the-page
There's really two main options:
- Fixed Footer - the footer always is visible at the bottom of the page
- Pushed Footer - the footer is pushed to the bottom of the page even when the content doesn't fill the window
The easier of the two is the fixed footer.
Fixed Footer
To make the footer fixed, in CSS set the footer's position to fixed position:fixed
and position the footer to the bottom of the page bottom:0px
. Here's a code snippet from CSS-Tricks.
#footer { position:fixed; left:0px; bottom:0px; height:30px; width:100%; background:#999; } /* IE 6 */ * html #footer { position:absolute; top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px'); }
Pushed Footer
A pushed footer is a bit trickier. Here's a great graphic showing why the footer doesn't stay at the bottom of the page when there isn't enough content:
Basically, the problem is happening because the footer element is 'pushed' under the element that is above it and the height of that element isn't as long as the height of the page. In order to fix this, you need to make sure that the footer gets 'pushed' down the full height of the page (minus the height of your footer).
Here's how to do it:
HTML
<div id="container">
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
</div>
CSS
html, body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
Here's a more detailed tutorial on how to do it as well as the source of the code above.
And here's a working demo of the code from the same source.
https://zhuanlan.zhihu.com/p/22936824?refer=nangit
http://blog.csdn.net/m0_38099607/article/details/71598423
这篇文章中的flex可以尝试一下。
需要解决的问题:测试的时候,这两种情况都要测试到
1.在页面内容不够的时候,footer的高度会变高。
2.在页面内容足够的时候,footer会覆盖掉content。
相关文章
- HTTP Status 400 - description The request sent by the client was syntactically incorrect.
- css - 去掉图片下的白边
- 【异常】[ERROR] The cloud assistant is not installed on the ECS, or the cloud assistant is unavailable. cloudassistant is uninstall
- Reporting Service 服务启动时报错The service did not respond to the start or control request in a timely fashion
- css 文本超出2行就隐藏并且显示省略号
- 前端学习 -- Css -- 选择器的优先级
- 前端学习 -- Css -- 样式的继承
- 前端学习 -- Css -- 否定伪类
- [RxJS 6] The Catch and Rethrow RxJs Error Handling Strategy and the finalize Operator
- [CSS] Target empty elements using the :empty pseudo-class
- [CSS3] Target HTML Elements not Explicitly set in the DOM with CSS Pseudo Elements (Blockquotes)
- [CSS] Target empty elements using the :empty pseudo-class
- [CSS] Make element not selectable
- [CSS3] Using CSS Combinators to Identify Siblings and Descendants in CSS
- 解决The type or namespace name 'XXXX' does not exist in the namespace 'XXXXXXXXX' 的错误
- 为什么CSS这么难学?css核心知识点攻坚指南
- Atitit.css 规范 bem 项目中 CSS 的组织和管理
- Unexpected XML declaration. The XML declaration must be the first node in the document and no white
- 已解决The method is not allowed for the requested URL.
- EnvironmentNotWritableError: The current user does not have write permissions to the targe...
- 【CSS】CSS 背景设置 ② ( 背景位置 | 背景位置-方位值设置 )
- 【CSS】CSS 复合选择器 ④ ( 链接伪类选择器 | a:link 默认样式 | a:visited 已访问样式 | a:hover 鼠标移动样式 | a:active 选定链接样式 )
- css利用padding-top设置等比例遇到的问题
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- [TroubleShootin]The backup set holds a backup of a database other than the existing 'xxdb' database.
- CSS优先级
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
- (六)Jenkins部署项目报错The username you provided is not allowed to use the text-based Tomcat Manager (error
- 【异常】Flink整合ES出错,The implementation of the provided ElasticsearchSinkFunction is not serializable.