All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Sticky Footer Using jQuery And CSS

Last Updated : Jul 1, 2023

IN - jQuery CSS HTML | Written & Updated By - Riya

In this tutorial we will show you how to create sticky footer using jQuery and CSS, sticky Footer is always be the main issue in web design it is difficult to create a footer that always remain in bottom and function properly and same on different screen sizes we solve that problem.

You may also like sticky header using jQuery And CSS.

Sticky Footer Using jQuery And CSS

To Create Sticky Footer It Takes Only Two Steps:-

  1. Make a HTML file and define markup and scripting
  2. Make a CSS file and define styling

Step 1. Make a HTML file and define markup and scripting

We make a HTML file and save it with a name footer.html

<html>
<head>
<link rel="stylesheet" type="text/css" href="footer_style.css">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
 var footer_height=$("#footer").height();
 $("#wrapper").css({'padding-bottom' : footer_height});
});
</script>
</head>
<body>
<div id="header">
 <p>TalkersCode.com</p>
</div>

<div id="wrapper">
 <h1>Sticky Footer Using CSS And jQuery</h1>
</div>

<div id="footer">
 <p>TalkersCode.com</p>
</div>
</body>
</html>

In this step we create three div for header, content and footer and we add document.ready() function to get footer height and set that height to wrapper padding to adjust the padding dynamically.

You may also like auto scrolling page using jQuery.

Step 2. Make a CSS file and define styling

We make a CSS file and save it with a name footer_style.css

body
{
 text-align:center;
 width:100%;
 margin:0 auto;
 padding:0px;
 font-family:helvetica;
 min-height: 100%;
 position: relative;
 background-color:#BCA9F5;
}
#header
{
 background-color:#8258FA;
 height:70px;
 line-height:70px;
 font-size:35px;
 color:white;
}
#wrapper
{
 text-align:center;
 margin:0 auto;
 padding:0px;
 width:995px;
 position: relative;
 padding-bottom: 70px;
}
h1
{
 margin-top:100px;	
 color:#8258FA;
 font-size:45px;
}
h1 p
{
 font-size:16px;
}
#footer 
{
 position: absolute;
 bottom: 0;
 width: 100%;
 left: 0px;
 height: 70px;
 background-color:#8258FA;
 color:white;
}
#footer p
{
 margin-top:15px;
 font-size:30px;
}

In this step we add the position 'relative' to our body tag and wrapper tag and then add position 'absolute' to our footer to make our footer stick to bottom.You may also like smooth scrolling to div using jQuery.

Thats all, this is how to create sticky footer using jQuery and CSS. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

I hope this tutorial on sticky footer using jQuery and CSS helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪