Home > Web Front-end > HTML Tutorial > A simple way to implement the html footer at the bottom of the page

A simple way to implement the html footer at the bottom of the page

高洛峰
Release: 2017-02-22 11:18:43
Original
1618 people have browsed it

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>
Copy after login

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预留的空间*/     
}
Copy after login

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]-->
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template