How to keep the footer of the page at the bottom?

Source: Internet
Author: User

The following code for page layout, except for the globaliner iner and dynamiccontent parts, is fixed in size.

Globalcontainer has an initial value of 774px and is automatically adjusted based on the resolution and display of IE menus. Dynamiccontent is dynamically calculated to ensure that footer is always at the bottom.

 

<! Doctype
Html
Public "-// W3C // dtd html 4.0 transitional // en">

<HTML>

<Head>

<Title> </title>

 


<Style
Type = "text/CSS">


Body

{


Padding: 0px;


Margin: 0px;

}

 


# Globalcontainer

{


Width: 100%;


Height: 774px;


Padding: 0px;


Margin: 0px;

}

 


# Maincontent

{


Min-width: 1280px;


Height: 100%;

}

 


# Head1

{


Width: 100%;


Height: 100px;


Background-color: Gray;

}

 


# Head2

{


Width: 100%;


Height: 100px;


Background-color: Aqua;

}

 


# Footer

{


Width: 100%;


Height: 100px;


Background-color: Silver;

}


</Style>


<Script
Type = "text/JavaScript" src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.3.min.js"> </SCRIPT>

</Head>

<Body>

<Div
Id = "globalcontainer" class = "globalcontainer">


<Div
Id = "maincontent">


<Div
Id = "head1">

This is head1


</Div>


<Div
Id = "head2">

This is head2


</Div>


<Div
Id = "dynamiccontent">

This is dynamic content


</Div>


<Div
Id = "footer">

This is footer.


</Div>


</Div>


</Div>


<Script
Type = "text/JavaScript">


// Set footer location

$ (Function (){

Setfooterposition ();

});

 

$ (Window). Resize (function (){

Setfooterposition ();

});

 


Function setfooterposition (){

$ (". Globalcontainer" ).css ("height", document. Body. scrollheight-5 );


VaR mainareaheight = $ ("# maincontent"). Height ();


VaR headerheight = $ ("# head1"). Height ();


VaR header2height = $ ("# head2"). Height ();


VaR containerheight = $ ("# dynamiccontent"). Height ();


VaR footerheight = $ ("# footer"). Height ();

 


VaR innerheight = headerheight + header2height + containerheight + footerheight;


VaR outerheight = headerheight + header2height + footerheight;


If (mainareaheight> = innerheight ){

$ ("# Dynamiccontent"). Height (mainareaheight-outerheight );

}


Else {

$ ("# Dynamiccontent"). Height ("Auto ");

}

}

 


</SCRIPT>

</Body>

</Html>

 

This layout ensures that footer is always at the bottom and mainly handles the following situations:

1. The page content is very short.

2. The page content is very long.

3. The page is not maximized.

4. From maximization to non-maximization,

5. The page changes from non-maximized to maximized

 

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.