How to place the footer tag at the bottom of the page

php中世界最好的语言
Release: 2018-01-23 10:41:34
Original
5331 people have browsed it

This time I will show you how to place the footer tag at the bottom of the page. What are the precautions? Here are the actual cases, let's take a look.

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%. The footer is set to be absolutely bottom (bottom: 0) relative to the position of the parent layer. The height of the footer must be reserved in the parent layer.

html code:

<!-- 父层 -->     
<div id="wapper">     
    <!-- 主要内容 -->     
    <div id="main-content">     
    </div>     
    <!-- 页脚 -->     
    <div id="footer">     
    </div>     
</div>
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 processed separately:

<!--[if IE 6]->     
<style>     
#wapper{height:100%;} /* IE在高度不够时会自动撑开层*/     
</style>     
<![endif]-->
Copy after login

I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

How to make mobile web page content adaptive

How to deal with content overflow in the table table

What are the differences between iframe and frame in HTML

The above is the detailed content of How to place the footer tag at the bottom of the page. For more information, please follow other related articles on 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!