Home > Article > Web Front-end > A simple way to implement the html footer at the bottom of the page
Requirements: Sometimes, when the page content is short and cannot support the height of the browser, but you want the footer to be at the lowest end of the window.
Idea: The minimum height of the footer's parent layer is 100%, and the footer is set to be absolutely bottomed (bottom: 0) relative to the position of the parent layer. , the height of the footer must be reserved in the parent layer.
html code:
<!-- 父层 --> <p id="wapper"> <!-- 主要内容 --> <p id="main-content"> </p> <!-- 页脚 --> <p id="footer"> </p> </p>
CSS is as follows:
#wapper{ position: relative; /*重要!保证footer是相对于wapper位置绝对*/ height: auto; /* 保证页面能撑开浏览器高度时显示正常*/ min-height: 100% /* IE6不支持,IE6要单独配置*/ } #footer{ position: absolute; bottombottom: 0; /* 关键 */ left:0; /* IE下一定要记得 */ height: 60px; /* footer的高度一定要是固定值*/ } #main-content{ padding-bottom: 60px; /*重要!给footer预留的空间*/ }
At this time, other browsers can display normally , but IE 6 needs to be dealt with separately:
<!--[if IE 6]-> <style> #wapper{height:100%;} /* IE在高度不够时会自动撑开层*/ </style> <![endif]-->
The above simple implementation method of placing the html footer at the bottom of the page is all the content shared by the editor. I hope it can help It is a reference for everyone, and I hope everyone will support the PHP Chinese website.
For more related articles on the simple implementation method of placing the html footer at the bottom of the page, please pay attention to the PHP Chinese website!