Creating a Fixed Footer with CSS

Another question on the same topic, with a twist. Despite trying various solutions found in countless articles, none seem to work for me. My familiarity with HTML/CSS is limited due to just a few months of off-and-on practice. Hence, I'm seeking help from someone knowledgeable who can guide me through this dilemma.

The blog layout I'm creating appears almost perfect except for the stubborn footer. It refuses to stick to the bottom. Instead, it hovers in the middle of the page's content. Ideally, I want a footer that anchors itself at the bottom and only displays when the content is minimal, akin to the layout seen on this website. Achieving this without resorting to 'position:fixed' has been my goal, but so far, I've hit roadblocks. As an amateur in web development, I feel lost in understanding what's going wrong.

I've included snippets of my current code, though they have been modified several times following different tutorials—none yielding the desired outcome.

If there are other errors or oversights unrelated to the sticky footer conundrum, experienced eyes spotting them would be immensely helpful in guiding me towards rectifying those mistakes. Any assistance provided will be greatly appreciated as I strive to learn the correct methods.

Thank you!

<body>
    <div id="outer">
        <div id="header">
            <div id="wrap">
                <div class="logo"><a href="#"><img src="images/logo.png" /></a></div>
            </div>
        </div>
        <div id="wrap">
            <div id="content">

                <div class="featured_title"><a href="#">Example Title One</a></div>
                ...

            </div>
        </div>
        <div id="wrap">
            <div id="sidebar">
                <div class="job_search">
                    <a href=#"><img src="images/job_search.png" /></a>
                </div>
                ...
            </div>
        </div>
        <div id="footer">
        
        </div>
    </div>
</body>

And here's the accompanying CSS:

html {
height:100%;
padding:0;
height:100%;
}

body {
margin: 0 0 40px;
background: #f4f4f4;
height:100%;
}


#wrap {
margin: 0 auto;
width: 940px;
}

/* Header */

...

/* Sidebar */
...
.job_search {
padding-bottom:20px;
}

/* Footer */

#footer {
clear:both;
bottom:0;
background:#000;
width:100%;
height:35px;
margin-top: -100px;
position:relative;
}

.footer_content {
font-family:helvetica, sans-serif;
color: #68acc2;
}

Answer №1

Give this a shot:

#footer{position:absolute; bottom:0;}

Answer №2

this is not the correct response

 <!--closing logo div--!> 

should be

<!-- end logo div -->

give this a try

<div id="wrapper">
    <div id="main" class="clearfix">
    </div>
 </div>

<div id="footer">
</div>

CSS styling

html, body, #wrapper{ height: 100%; }
body > #wrapper{height: auto; min-height: 100%;}
#main { padding-bottom: 150px; }  /*  same height as the footer */
#footer { 
        position: relative;
    margin-top: -150px; /* negative value of footer height */
    height: 150px;
    clear:both;} 

.clearfix:after {content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;}
.clearfix {display: inline-block;}

Answer №3

After encountering the same problem and spending countless hours troubleshooting, I finally managed to create a sticky footer solution that stays at the bottom of any window without overlapping any content. The best part is that it adjusts to different window sizes and stops at the end of the content seamlessly.

If you're struggling with a similar issue, feel free to check out my jsfiddle example:

http://jsfiddle.net/juroto/HL6Ad/

You can see how I implemented it and use the code for your own projects! :D

While reviewing your code, I noticed some areas that need attention. Fixing HTML tags, removing unnecessary </div> elements, and correcting CSS properties like adding a missing semicolon are crucial steps. It's essential to simplify your code and focus on getting the sticky footer working before reintegrating other components. You can start fresh with a basic structure and gradually build upon it once the footer is functioning correctly. Take a look at the simplified structure below for reference:

<!doctype html>

    <head>

        <title>INSERT TITLE</title>

        <style>
            body {
                margin: 0;
                padding: 0;
                height: 100%;
            }
            html {
                height: 100%;
                margin: 0;
                padding: 0;
            }
            * html #wrapper {
                height:100%; 
            }
            #wrapper {
                min-height: 100%;
                position: relative;
            }
            #content {
                padding-bottom: 30px; /* ATTENTION! padding-bottom should be equal to the footer height (this keeps the footer from overlapping the content) */
                font-size: 10em; /* ATTENTION! this font-size can be deleted or changed to whatever your heart desires*/
            }
            #footer {
                position: absolute;
                width: 100%;
                clear: both;
                bottom: 0;
                padding: 0;
                margin: 0;
                /* ATTENTION! The following elements below 
                can be set to whatever your heart desires */
                height: 30px; /* REMEMBER #footer height = #content padding-bottom */
                background: #333;
            }
        </style>

    </head>

    <body>
        <div id="wrapper">
            <div id="content">INSERT CONTENT HERE</div>
            <div id="footer"></div>
        </div>
    </body>
</html>

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

Please provide an explanation for the statement "document.styleSheets[0].cssRules[0].style;"

I'm seeking an explanation for this block of code: document.styleSheets[0].cssRules[0].style; It would be helpful if you could use the following code as a reference: * { padding: 0; margin: 0; box-sizing: border-box; font-family:&apos ...

Can a Django form be configured to hide submitted values using display:none?

As I was working on submitting a form in Django with multiple details, I came up with the idea to split it into sections. The first set of details would be hidden initially, and upon clicking the next button, the next set of details would be displayed fo ...

When the ajax response comes in, my javascript code seems to suddenly stop

After sending a POST request, my JavaScript suddenly stops working for some unknown reason. Here's the situation: I visit my webpage, fill out the form, and then click 'Click me' : Upon clicking OK in the alert popup, I see the expected ou ...

-=:Heading with a decorative vertical line=:-

Currently, I am working on a CSS project that requires page titles (headings) to be centered with horizontal lines positioned vertically on both sides. Additionally, there is a background image on the page which means the title's background must be tr ...

What steps can be taken to prevent a wrapper's CSS from affecting its enclosed elements?

My container div includes some opacity and auto height that I don't want to affect all elements within it. Is there a way to preserve the container's styles without impacting its contents? ...

Modifying the background hue of the element-ui tooltip

I am currently working with vue.js version 2.6.10 and element-ui version 2.15.1. The element-ui component I am using is as follows: <el-tooltip content="Top center" placement="top"> <span>Dark</span> ...

Calculation operations nested within each other

Looking for a solution here. I am trying to utilize the CSS calc operation to carry out two calculations: I aim to make my width equal to (100% / 7) - 2 But whenever I attempt multiple operations in a CSS calc function, it doesn't work: width: cal ...

Step by step guide on incorporating two background images in a single header

I'm looking to create a header with a background image that appears twice, like this: To achieve the effect, I added opacity of 0.5 to one of the images, but it is affecting everything in my header including text and logo. Is there a way to prevent t ...

Is there a way to identify if you are at the bottom row of a column defined by CSS styling?

I have implemented the new CSS-style column to divide a single unordered list into multiple columns. Now, I am trying to figure out how to target the last element in each column using JavaScript or CSS. Here is my HTML: <ul> <li /> <li ...

Swapping icons in a foreach loop with Bootstrap 4: What's the most effective approach?

I need a way to switch the icons fa fa-plus with fa fa-minus individually while using collapse in my code, without having all of the icons toggle at once within a foreach loop. Check out a demonstration of my code below: <link rel="stylesheet" href= ...

Revamping the design of a menu bar in WordPress

I designed a navigation bar and now I'm looking to customize the CSS for it in WordPress. Specifically, I want to be able to reference the nav bars by name from PHP to CSS. It seems like there are just two dots representing variables. Here is the co ...

Strange occurrences with the IMG tag

There seems to be an issue with my IMG element on the webpage. Even though I have set the height and width to 100%, there is some extra space at the end of the image. You can view the problem here: I have also included a screenshot from the developer too ...

What is the best way to make a child div's height match its parent's height?

I am facing an issue with aligning 2 divs on the same line, separated by a vertical line while ensuring that the line always has the height of the parent div. Despite trying various solutions suggested online, none seem to work for me. I cannot use positi ...

Having trouble removing lines from Router Link? Unfortunately, using style={{'textDecoration': 'none'}} doesn't seem to be doing the trick

Does anyone know why the text decoration is not working on my link when I use text-decoration none? Any solutions or suggestions would be greatly appreciated. Thank you in advance! Navbar.js file import React,{useState} from "react"; import { mak ...

CSS 3 - Apply transition to the 'display' property

I have a question about using the transition effect in conjunction with the display property: Currently, I am testing on Safari. input.input_field { display:none; transition-property: display; transition-duration: 2s; -webkit-transition-p ...

The function getSelection().focusNode does not function properly within a specified ID

My current code allows for text to be bolded and unbolded using Window.getSelection(). I found the initial solution here: Bold/unbold selected text using Window.getSelection() It works perfectly without any issues. However, when I tried to modify the code ...

Error in viewpoint/transformation transition on Microsoft Edge

Encountering a peculiar issue with MS Edge involving the animation of a door (a div tag) around the Y axis using the css rotateY() function in combination with perspective properties. The problem arises when transitioning an angle from a positive value to ...

Choosing particular contenteditable divisions using jQuery

Consider the following HTML structure for a specific type of blog post editor: <div class="entry"> <div class="title" contenteditable="true"> <h2>Title goes here</h2> </div> <div class="content" contenteditable ...

creating an interactive element that seamlessly integrates with a dynamic background image slideshow

Struggling to make this work correctly as a newbie in javascript. I need the background image to slide upon hover and stay active on its selected div when clicked. The html, css, and javascript I have currently work fine - when the user clicks on a div, a ...

Having trouble with the alignment of the product grid on Woocommerce with the Wootique theme?

Hey there, I've been facing an issue with the woocommerce product display grid layout. The items keep getting misaligned, with one on a line and the others right next to each other. I attempted to fix it by adding some custom CSS code: .woocommerce ...