Placing the footer at the bottom of the webpage

I am struggling to place the footer at the bottom of the page (or screen if the page is shorter than a screen). Here is the code I am currently using:

<div id="wrapper">
    <div id="header-wrapper">
    ...
    </div> <!--header-wrapper-->

    <div class="clear"></div>

    <div id="body-wrapper">
        <div class="row960">

            <div class="menu">...</div>

            <div class="content">...</div>

        </div> <!--row960-->
    </div> <!--body-wrapper-->

    <div class="clear"></div>

    <div id="footer-wrapper" class="gray">

    </div> <!--footer-wrapper-->

</div> <!--wrapper-->

Along with the corresponding CSS:

.clear{
    clear:both;
    display:block;
    overflow:hidden;
    visibility:hidden;
    width:0;
    height:24px;
    margin:0px
}

html, body{
    margin: 0;
    padding: 0;
    height: 100%;   
    width: 100%;
}

body{
    background-color: #000000;
    color: #FFFFFF;
    font-size: 14px;
}

#wrapper{
    min-height: 100%;
    position: relative;
}

#header-wrapper{
    height: 100px;
}

#body-wrapper{
    padding-bottom: 50px;
}

#footer-wrapper{
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50px;
}

.row960{
    width: 960px;
    margin: auto;
    overflow: auto;
}

#menu{
    width: 200px;
    float: left;
}

.content{
    width: 740px;
    margin-left: 20px;
    float: right;
}

The issue arises when the page exceeds the length of a screen and causes the footer to overlap the content below. Upon inspection with Firebug, it seems that the row960 element does not have the correct height. I'm stumped on how to resolve this. Any suggestions?

You can access my page at

Thank you for any assistance!

EDIT: Just to reiterate, the main issue lies in the incorrect height calculation of the row960 element.

Answer №1

After reviewing your requirements, I believe I have come up with a suitable solution. However, there may be other methods that suit your needs better, so feel free to explore other options if necessary. (I did notice that on your website, the #wrappper element is actually a sibling of #footer-wrapper, rather than a parent as stated.)

Based on the structure of your site, the HTML code would look like this:

<div id="wrappper">
    <div id="header-wrapper" class="gray">
    <div class="clear"></div>
    <div id="body-wrapper"></div>
    <div class="clear"></div>
    <div class="spacer"></div>
</div>
<div id="footer-wrapper" class="gray"></div>

Make sure to include the .spacer element at the bottom of #wrappper, as it is essential for implementing the "sticky footer" technique.

In terms of CSS, you will need to add the following styles (append to existing definitions if applicable):

body, html{
    height: 100%;
}
#wrappper{
    min-height: 100%;
    margin-bottom: -50px;
    height: auto;
}
.spacer{
    height: 50px;
}

The height of 50px for the spacer is based on the height of your footer element, #footer-wrapper.

I have only tested this in the Firebug console, so I cannot guarantee its performance in a live environment. However, I am confident that this solution will meet your requirements. If you require further assistance or if this solution does not meet your expectations, please do not hesitate to reach out. I am here to help!

Answer №2

To position it at the bottom, simply let it flow naturally within your div without using position:absolute or bottom:0.

Answer №3

If you want to achieve this effect, using margin could be the solution. Check out this fiddle for a visual representation: http://jsfiddle.net/8WLyP/

The concept is to encapsulate all your content within a "container" element in your HTML, with the footer positioned as a sibling of that container.

In your CSS, ensure to assign min-height: 100% to both the html and body elements, as well as the "container" element.

Set a specific height (denoted by X) for the footer, like 50 pixels in the example provided. Then apply margin-bottom: -50px to the "container" element to create the desired spacing.

It's crucial not to add any additional margins or paddings to "container" and "footer" beyond what's specified. If necessary, apply them to child elements, such as the p element in this case.

This technique ensures that the footer remains at the bottom of the window when the content is insufficient, yet moves along with the content if it extends beyond the viewport.

Here's an example of the HTML structure:

<div id="container">
    <header>
        <p>Header</p>
    </header>
    <section>
        <p>Section</p>
    </section>
</div>

<footer>
    <p>Footer</p>
</footer>

And the corresponding CSS:

html, body, header, footer, section, p, div {
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

p {
    padding: 5px 10px;
}

header {
    width: 100%;
    background: #f00;
    color: #fff;
}

section {
    width: 100%;
    height: 200px;
    background :#0f0;
    color: #fff;
}

#container {
    width: 100%;
    min-height: 100%;
    margin-bottom: -50px;
}

footer {
    width: 100%;
    background :#00f;
    color: #fff;
    height: 50px;
}

Answer №4

If you're looking to position the footer at the bottom of your content, but also want it to stick to the bottom of the viewport if the content is shorter, here's a solution for you:

Here's the CSS code to achieve this effect:

#footer-wrapper {
    position: relative;
    width: 100%;
    height: 50px;
}

#body-wrapper {
    position: relative;
    height: 100%;
}

Additionally, you can use this JavaScript (jQuery) snippet:

var bodyWrap     = $('#body-wrapper'),
    footerWrap   = $('#footer-wrapper'),
    windowHeight = $(window).height();

var heightRemaining = parseInt(windowHeight - bodyWrap.outerHeight() - footerWrap.outerHeight());

if (heightRemaining > 0) bodyWrap.css('min-height', heightRemaining);

Please note that I haven't had the opportunity to test this code thoroughly yet.

Feel free to implement and give it a go!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discovering the method to extract text from an element within a search result with Selenium Webdriver

Struggling to extract a URL from Tripadvisor.com's search results using its element, my attempts have proven futile so far. Check out the code snippet below: from selenium.webdriver.common.keys import Keys from selenium import webdriver from seleniu ...

Sending Input to SQL DataBase Using C# and HTML

I need to execute a C# function when a button is clicked that captures a rating (1-7) and saves it to a database along with a text input. Here is the feedback section: <asp:PlaceHolder ID="AnswersPlaceholder" runat="server" Visible="false"> <asp ...

The function onClick does not function properly when used with the <p> element, but it works flawlessly with the <button> element

export function SignoutButton() { return ( <p onClick={() => signOut({ callbackUrl: "/" })}> <IoIosLogOut /> Logout </p> ); } I was struggling with a function in my next.js project that wasn't wo ...

The automatic selection process for IE document modes

It may seem simple, but I'm a little perplexed about how IE decides which browser mode to use. In IE9, there are options such as IE9 Compatibility Mode, IE9, IE8, and IE7. These modes are selected automatically depending on the webpage. Can someone e ...

Unauthorize entry to several documents using htaccess

I want to restrict access to multiple files using htaccess. <FilesMatch (profile|reg|register|..............|)\.php> order allow,deny deny from all </FilesMatch> There are 6 folders with around 30 files each that I need to block access t ...

Exploring the possibilities of applying CSS to customize the color of various elements

Is there a way to set the color of elements in CSS so that it applies to everything such as fonts, borders, and horizontal rules when applied to the body? How can I accomplish this effectively? ...

Targeting child elements with CSS selectors

In my ecommerce software, I have a menu that I want to customize by making the main categories bold. I have attempted various methods, including the ones shown below, but I am struggling to target the correct elements (specifically those in capital letter ...

Issue with displaying modal and backdrop specifically on iPhone in Angular 13

Within our Angular 13 application, we have a modal component. The component's CSS includes the :host selector for the root element, which also serves as the style for the backdrop: :host { position: absolute; background: rgba(0, 0, 0, 0.5); widt ...

The conditional CSS file does not have precedence over the regular CSS file

Currently, my approach involves using conditional comments to connect to a CSS file named "IEonly.css" if the Internet Explorer version is not greater than 8. My goal is to modify certain properties in the standard CSS file. Oddly enough, IEonly.css effect ...

Preserving form input after an unsuccessful submission: A simple guide

As a beginner in the coding world, I am currently working on creating a contact form using PHP. One of the features I've included is a reCaptcha that must be checked before submitting the form. However, if the user forgets to check the reCaptcha and h ...

html5sql - Struggling to establish a connection with my database

I recently started using html5sql.com for my html5 DB needs and I must say, it's a fantastic module! However, I've hit a roadblock. In my index.html/index.js file, I have set up my database and created tables in it. try { html5sql.open ...

Through the implementation of JavaScript, the element's class is dynamically altered

While working on my project, I encountered an issue with implementing a change in the class of an element using JavaScript. The problem is that when I click on the home page, the last page does not get deselected. Here is my current JavaScript code: const ...

Struggling to style a nested table using CSS

Please take a look at this JSFiddle example for reference. I am currently working with tablesort and its associated CSS to achieve alternating row colors for the rows containing first and last names. Additionally, I want the rows within the sub-table disp ...

Animate failed due to the appending and adding of class

$('#clickMe').click(function() { $('#ticketsDemosss').append($('<li>').text('my li goes here')).addClass('fadeIn'); }); <link href="http://s.mlcdn.co/animate.css" rel="stylesheet"/> <script ...

Utilizing icons for form-control-feedback in Bootstrap 4

I am struggling to achieve the desired display using Bootstrap 4 form-control feedback styling. The goal is to include an icon inside the input field along with an error message. My current setup includes Angular 5.2.9, Bootstrap 4, and Fontawesome icons. ...

Switch from monochrome to color when hovering inside a clipping mask

I have successfully mastered the technique of changing an image from grey to color on hover using CSS and JavaScript. However, I am curious about whether it is possible to achieve the same effect using a clipping mask. Attached is an image that illustrate ...

The spacing in a nested flexbox form gets distorted due to CSS3 styling

Working on creating a flexbox form where labels and inputs are on the same line. Have successfully achieved the desired layout using flex properties like flex-basis. However, encountered an issue when trying to nest the flexbox within an element with a fi ...

Recommendations for a UI library specializing in displaying analytical graphs

Looking to create analytical graphs of tweets similar to the site found at the following link Website-Link Curious about the top open source options available for this task? I've heard good things about Raphael.js. Any other recommendations? ...

The filter is displaying incorrect categories

I am facing an issue with creating a work filter based on the last column which represents categories. When I select an option from the dropdown, I want to display only that specific category and hide the others. Currently, when I try clicking on an option ...

Steps to hide a div after it has been displayed once during a user's session

After a successful login, I have a div that displays a success message and then hides after 4 seconds using the following JavaScript code: document.getElementById('success').style.display = 'none'; }, 4000); While this functionality wo ...