Creating a sticky footer with an additional element using CSS

As I work on building my own website for showcasing my art portfolio, I came across a helpful resource at . However, I am facing some challenges when trying to incorporate an additional element into it.

The current HTML structure looks like this:

<html>
<head>
    <link rel="stylesheet" href="style.css" ... />
    <link rel="stylesheet" href="layout.css" ... />
</head>
<body>
    <div class="wrapper">
        <p>Your website content here.</p>
        <div class="push"></div>
    </div>
    <div class="footer">
        <p>Copyright (c) 2008</p>
    <img src="image.png>    
    </div>
</body>

I am also using the following style.css:

.wrapper {
position: relative;
width: 800px;
margin: 0 auto -50px;
}

.footer {
position: relative;
width: 100%;
margin: 0 auto;
padding: 0;
background-color:#000000;
text-align:center;
}

.footer img {
position: relative;
width: 400px;
top: -238px;
margin: 0 auto;
} 

.footer a {
color: #fff;
text-decoration: underline;
border: 0;
}

.footer p {
position: absolute;
left: 0;
bottom: 4px;
width: 100%;
padding: 0;
color: #fff;
font: 0.8em arial,sans-serif;
}

In addition, I have a layout.css file with the following code:

* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -50px;
}
.footer { 
 height: 50px;
} 

.push {
height: -100px;
}

While attempting to create a sticky footer design with an image that overlaps the main content when the window is resized, I encountered difficulty eliminating unwanted negative space caused by the existing code. Do you have any suggestions?

**Update: After overcoming the initial obstacle, I realized that the original sticky-footer tutorial created a fixed footer within the border of the main body. What I actually wanted was a top-layer fixed footer that extends over the main body and includes a bottom border element. By making adjustments in both the HTML and CSS, I found a solution:

<div class="footer">        
    <img src="Image.png" width="400" height="238" />
    <div class="bottom-border">
        <p>Copyright (c) 2008</p>
    </div>
</div>

and updated CSS styling:

.footer img {
position: relative;
width: 400px;
margin: 0 auto;
} 

.bottom {
position: relative;
width: 100%;
height: 20px;
margin: 0 auto 0;
padding: 0;
text-align:center;
background-color: #000000;
}

Following the guidelines proposed in the 'layout.css' comments included in the sticky-footer tutorial, I synchronized the heights of .wrapper, .footer, and .push elements accordingly.**

Answer №1

Sorry for the delay, but I'm here to help! The issue you're experiencing is due to your image still occupying the same space on the page despite being placed above the footer. To solve this, use position:absolute;.

Check out a working example here

I made these modifications:

.footer img { 
  position:absolute; 
}

.footer p {
  position: relative;
  height:4em;
}

By using position:absolute;, the element will be positioned based on the last non-static (default) element and will no longer affect the page layout. In this case, it will be positioned at .footer without taking up any additional space.

Additionally, changing to absolute can disrupt centering, as margin:0 auto; will not work on position:absolute; elements. To fix this, add the following rules:

.footer img {
  left:50%;
  margin-left:-200px;
}

Answer №2

If you're looking for a simple solution for a sticky footer, here's an easy one. Just add height: 100% to both the body and html elements. Then set the wrapper to display: table. You can insert any content or element inside the .w1 element.

And the footer will adjust flexibly as well.

Check out the code snippet below:

html{height:100%;}
body{
    margin:0;
    height:100%;
    background: #ccc;
}
#wrapper{
    width:100%;
    height:100%;
    display:table;
    margin:0 auto;
}
#footer{
    width:100%;
    overflow:hidden; /*for FF on Windows 7*/
    display:table-footer-group;
    height:1%;
    background: #333;
    color: #fff;
}
<div id="wrapper"> <!-- table -->
    <div class="w1">
        <p>header and content of the page</p>
    </div>
    <div id="footer"> <!-- table-footer-group -->
            <p>footer content</p>
    </div>
</div>

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

Having trouble applying styles to a component using forwardRef

I'm relatively new to React and still trying to wrap my head around the component's lifecycle. However, the issue at hand is proving to be quite perplexing. One thing that confuses me is why adding "setState(10);" causes the style of the "Test" ...

Having trouble with getting the background image URL to work in Django CSS?

Hey there, I'm having an issue with my header-task class. The background-image doesn't seem to be showing up, even though when I click the URL in Visual Studio Code, the image displays. Can anyone help me figure out what's going wrong with m ...

What is the best way to eliminate the space between columns?

I have a simple structure on BootStrap. <div class="container"> <div class="row"> <div class="col-md-4 blue-section" ><p>Some content</p></div> <div class="col-md-4 red-section"><p>Some content&l ...

Struggling to set the background color for a div element

I am dealing with the following HTML and CSS: <div id="com_loaded"> <div id="com_loaded_userpic"><a href="#" class="tooltip"><img src="pic.jpg" class="img_poster" /><span>Username</span></ ...

Creating an Efficient Lazy Loading HTML Page with jQuery

I've been looking to create a page that loads content only as the user scrolls to that specific section, similar to the way Pinterest website functions. Does anyone have suggestions on how to design and implement this feature, or know of any plugins ...

JavaScript Logic to Check if an Element is Hidden

I'm having trouble figuring out how to close an element when another element collapses. I've searched for solutions without success. My structure is updated using Bootstrap and JavaScript, but it doesn't function as expected. Specifically, ...

Adjusting Font Size of Menu BarORModifying

I'm currently using WordPress to build my website. If you'd like to take a look, here is the link: I'm trying to make the font size smaller to accommodate more menu bars on the site. Any suggestions on how I can achieve this would be great ...

The challenge with linking within Layerslider

Having some trouble with an external link to a specific layerslider slide (html version, NOT wordpress). Here is the webpage in question: After reaching out in the support forum, I was advised to use this javascript: <a href="javascript:void(0);" onc ...

Sending array values from a dynamic input field in Angular 4 and processing them accordingly

I am currently exploring options on how to add and delete multiple input fields. When a user submits two or more fields, I want the results to be displayed in an array. This is my HTML form: <form method="post" [formGroup]="formData"> ...

What is causing this code to keep iterating endlessly?

I have a basic jquery script embedded in my HTML code that utilizes the cycle plugin for jQuery. The problem I'm facing is that when I interact with the slideshow using the "next" or "previous" buttons, it continues to loop automatically after that in ...

Using AJAX to dynamically load an image by setting the image path as the source of the image tag

I'm facing a challenge with my AJAX call that is used to display user details in a modal. I recently integrated an image upload feature for users, but now I'm struggling to display the uploaded image. I have tried looking for solutions online, bu ...

When using onclick() with multiple functions, only the first function will be executed

I'm facing an issue where only the first function is being executed when I try to run two functions. It seems like changing an HTML variable value might be causing the javascript execution to stop. Here is the code snippet that I am running: HTML: & ...

Creating a pop-up effect for a div in the center of a table cell using HTML and CSS

I am currently working with Angular and facing a challenge where I need to display a div like a popup in a table cell when clicked. Despite having the click event logic in place, I am unsure of how to achieve this without using external libraries such as B ...

Creating a slanted polygon div that adjusts to different screen sizes: a step-by-step

Looking to create a slanted and responsive div similar to the example image provided. Any assistance would be greatly appreciated. ...

The ivory pillar on the far right extending over the entire width of the page

Struggling with Bootstrap to create responsive cards, I encountered a white column that's extending off the page and causing an annoying scroll to the right. Can anyone assist me in resolving this issue? If you have any suggestions on how to achieve ...

How can you create an ordered list with letters and parentheses using HTML5 and CSS?

Is it possible to use letters with ")" instead of "." in an ordered list format? For example: a) Some text... b) Some text... c) Some text... Currently, I am seeing: a.) Some text... b.) Some text... c.) Some text... I need to remove the periods. CSS: ...

Tips on extracting JSON information in JavaScript when the key name is unspecified

I have a challenge in parsing JSON data where the property name is unknown. Below is a snippet of my code, and I need your help in figuring out how to retrieve all data with an unknown property. datas.data.videoGroup.past, then utilize a loop $.each(data ...

Taking pictures on my website with the help of c#, HTML (excluding HTML 5), and javascript

My current project requires me to capture an image from a webcam, and I have been brainstorming solutions. However, there are specific conditions that I must adhere to in order to achieve the desired result: I am unable to utilize HTML5 due to compatibil ...

Tips on preserving CSS modifications made in Chrome Developer Tools Inspector to .vue file

Currently, I am in the process of setting up a new workflow where my goal is to streamline my work by using the Chrome DevTools Inspector to save any CSS changes directly to my .vue file. While the DevTools Workspaces feature can achieve this, it involves ...

Looking to incorporate multiple accordion drop down menus on your website? Utilize a combination of HTML, CSS, and JavaScript to

I am experiencing a challenge with implementing multiple accordion menus on my website. Whenever I attempt to duplicate the code, the new accordion menu appears but clicking on the first bar simply scrolls me back to the top of the webpage. Below is the H ...