CSS and JS fixed page bottom effect

Source: Internet
Author: User

HTML section:

The code is as follows Copy Code
<div id= "Wrap" >
<div id= "Header" >
</div>
<div id= "Main" >
</div>
</div>
<div id= "Footer" >
</div>css section:
HTML, body {height:100%;}
#wrap {min-height:100%;}
#main {overflow:auto;padding-bottom:150px}/* To be the same height as footer * *
#footer {position:relative;margin-top: -150px;height:150px;clear:both;}
/*opera compatible */
Body:before {content: ""; height:100%;float:left;width:0;margin-top:-32767px;}

As you can see, the HTML section is the same as the first method, except for a header section. Note here that the headers for both methods need to be added to the first part. The other is the writing of CSS, written on the compatibility of opera, here is ashamed I did not study the first method of the compatibility of opera. Interested friends can delve into.

In addition, the author also wrote the Compatibility for IE:

The code is as follows Copy Code

<!--[if! IE 7]>
<style type= "Text/css" >
#wrap {display:table;height:100%}
</style>
<! [endif]--> example does not have much to say


Look at another complete example.

The code is as follows Copy Code
<style type= "Text/css" rel= "stylesheet" >
html,body{padding:0;margin:0;overflow:auto;height:100%;width:100%}
#wrapper {Width:952px;margin:auto;display:block}
#presence {
bottom:0;
Display:block;
height:23px;
line-height:23px;
border:1px solid red;
width:950px;
z-index:100;
Position:fixed!important;
>position:absolute;
margin:0 Auto;
}
#main {
height:100%;
Overflow:auto;
position:relative;
width:100%;
}
#content {
margin:0;
min-height:100%;
padding:0;
position:relative;
BORDER:1PX solid blue;
height:3000px;
}
</style>
<body>
<div id= "wrapper" >
<div id= "Presence" > here is the bottom </div>
<div id= "Main" >
<div id= "Content" > here are the contents </div>
</div>
</div>
</body>


Another JavaScript implementation is recommended

The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<title> Position-fixed tool bar </title>
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<script language= "JavaScript" >
/*
Changes the display state of an object based on the current properties of the object
*/
function Onclickdiv (divid)
{
if (document.all[divid].style.display== ' none ')
{document.all[divid].style.display= ';}
Else
{document.all[divid].style.display= ' none ';}
return 0;
}
</script>
<style type= "Text/css" >
html,body {margin:0; padding:0; overflow:hidden;height:100%; width:100%; text-align:left;}
. body {position:relative; width:100%; height:100%; overflow-y:scroll; overflow-x:auto; cursor:default;}
. tools {position:absolute; z-index:100; margin:0 auto; bottom:10px; left:10px; width:400px; height:20px; border:1px Solid Gray; Background: #f7f7f7; Text-align:left;}
#dy2 {
Position:absolute;
height:100px;
width:200px;
Background-color: #000066;
Top: -100px;
Z-index:2;
}
#dy1 {
height:25px;
width:100px;
border:1px solid #990000;
Background-color: #FF9900;
Text-align:left;
}
</style>
<body>

<div class= "Tools" >
<div id= "Dy2" style=display:none> hidden </div>
<div id= "dy1" Style=display onclick= "return onclickdiv (' Dy2 ')" >LINKTALK</div>
</div>
<div class= "Body" >
<div style= "Height:1200px;background: #ffffff" ></div>
</div>
</body>


For more details please see: http://www.111cn.net/js_a/75/e7c8b29a29b0f45432c2fd0b449c7a9f.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.