Switching the position of a div to absolute completely destroys the design of the layout

I currently have a bottom div at the footer of my webpage. It features a background image and another div called bottomnav, which contains an unordered list for navigation.

However, when I try to change the position of bottomnav to absolute, the entire bottom div shifts up into the div above it. Interestingly, I have a separate div named cc that I can change to absolute without encountering any issues.

Here is my code snippet:

html

<div id="bottom">
        <div id="bottomnav">
            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="services.html">Services</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </div>
        <div id="cc">©2014 European Homemakers</div>
    

And here is the corresponding CSS:

#bottom {
        background-image: url(../Images/home_bottom.png);
        width: 960px;
        margin-left: auto;
        margin-right: auto;
        min-height: 100px;
        background-repeat: no-repeat;
        position: relative;
    }
    
    #bottomnav {
        font-size: 20px;
    }
    
    #bottomnav ul {
        list-style-type: none;
        height: auto;
    }
    
    #bottomnav li {
        display: inline;
        padding: 20px;
    }
    
    #bottomnav a {
        text-decoration: none;
        color: #FF9200;
    }
    
    #cc {
        text-align: right;
        color: #FF9200;
        position: absolute;
        bottom: 5px;
        right: 5px;
        font-size: 20px;
    }
    

I am relatively new to web design, so I am unsure why changing the position of bottomnav to absolute impacts the layout in this way.

Answer №1

Check out this Working Fiddle!

In the code snippet provided, it seems like there are a couple of issues that need attention. Firstly, make sure to properly close the #bottom div. Additionally, since the #bottom is set to position: relative, any elements inside it will be positioned absolutely relative to this div. Therefore, it's recommended to move the footer div outside of it.

Here is the HTML:

<div id="bottom">
    <div id="bottomnav">
        <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="services.html">Services</a></li>
            <li><a href="contact.html">Contact</a></li>
        </ul>
    </div>    
</div>
<div id="cc">©2014 European Homemakers</div>

And here is the CSS:

#bottom {
    background-image:url(../Images/home_bottom.png);
    width: 960px;
    margin-left:auto;
    margin-right:auto;
    min-height: 100px;
    background-repeat:no-repeat;
    position:relative;
}
#bottomnav {
    font-size: 20px;
}
#bottomnav ul {
    list-style-type: none;
    height:auto;
}
#bottomnav li {
    display:inline;
    padding:20px;
}
#bottomnav a {
    text-decoration: none;
    color: #FF9200;
}
#cc {
    color: #FF9200;
    font-size:20px;
    position: absolute;
    bottom: 5px;
    right: 5px;
}

Answer №2

If you want your footer to consistently remain at the bottom in relation to the content, this solution will assist you.

SEE DEMO

You must adjust your website structure accordingly.

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

Using data attributes for assigning them to a div container - a complete guide!

As I venture into the world of HTML5 and JS, I'm facing some challenges in finding success. My goal is to dynamically load data attributes from "li" elements into a div container, which will provide additional information for a slide within the flexs ...

Struggling with a dynamic HTML table using Mustache and Icanhazjs technologies

I am encountering an issue while attempting to construct a dynamic table using Icanhazjs (Mustache). The table data is consistently rendered outside the table tag, resulting in my data not being displayed within the table itself. To observe the output, pl ...

Expanding Material Ui menu to occupy the entire width of the page

I'm encountering an issue with a menu I created where I can't seem to adjust its height and width properly. It seems to be taking up the full width of the page. import React, { Component } from "react"; import Menu from "@material-ui/core/Menu"; ...

Pause jQuery at the conclusion and head back to the beginning

As a beginner in the world of jQuery, I am eager to create a slider for my website. My goal is to design a slideshow that can loop infinitely with simplicity. Should I manually count the number of <li> elements or images, calculate their width, and ...

Achieving full-screen fill with inline SVG

I recently purchased an svg graphic and exported it to a .svg file with the intention of using it in inline HTML. I placed it within the <body> tag of my document, but now I'm trying to make it fill the entire width and height of the screen. I&a ...

Exploring the document body with jquery

In my homescreen.jsp, I have a link that opens an iFrame when clicked. My goal is to hide the vertical scrollbar of homescreen.jsp when the iFrame is open. Using jQuery, I attempted to access the body of homescreen.jsp and was successful. However, I encou ...

Using jQueryUi Tabs for Organizing Div Tables

Recently, I implemented a jQuery tab on my website using the following code snippet: <div id="tabs"> <ul> <li><a href="#tabs-1">Basic Info</a></li> </ul> <div id="tabs-1"> ...

Stopped due to an error: TypeError - document.getElementById(...) is not defined

Currently, I am working on developing a commenting system. Everything seems to be functioning well as long as there is at least one existing comment. However, if there are no comments present and an attempt is made to create one, an error message pops up d ...

Encountered a MultiValueDictKeyError in Django at /employeeUpdate/ after making changes to the data

Encountering a django error "MultiValueDictKeyError at /employeeUpdate/ 'id'" after making changes to the data. Here is the code snippet from my views.py: def employeeUpdate(request): id = request.POST['id'] emp_username = requ ...

When you hover, a panel will slide in from the right. When you move the mouse

Hey everyone, I've been trying to implement the solution provided but I seem to be missing something. Can you take a look at my fiddle? http://jsfiddle.net/cancerian73/Ej5k8/ body { position: relative; min-height: 3000px; margin: 0; padding: 0; to ...

Is it possible to display images in PHP when the value matches the specified string?

Is there a faster and more efficient way to display one or multiple images if $value == $string? For instance, let's say I have a cell containing the string 'r o g'. If a user inputs ro, it should output <img src="red.gif"> and <im ...

Bulma table rows not extending to the complete width

In my angular7 app, I have implemented a is-fullwidth Bulma table that is functioning correctly. However, I now need to incorporate an angular component within each row, with the td tags contained in that component. The issue arises when I do this, as the ...

Angular 2: Emptying input field value on click event

I am experiencing an issue with resetting my input values. I have a search bar with filter functions. When I enter a value, it displays a list below and I want to add a function to these links. When I click on one of them, it takes me to another component ...

Utilizing JavaScript XHR to Organize Data Retrieved from an API

I have successfully connected FDA's Drug API with XMLHttpRequest() and now I need help sorting the fetched data in ascending order based on its GENERIC NAME (results["open_fda"].generic_name). Importing all arrays from the API seems impractical, even ...

Simply upload a file and send it to a specific URL by using the drag and drop functionality in HTML

After successfully implementing the drag and drop functionality, my next challenge is figuring out how to upload and post the file to a URL with specific parameters. Usually, if I had a form available, I could do it like this: <form enctype="multipart ...

Swapping images when hovering over a list item or anchor tag

I recently came across an intriguing issue with changing the img src on a:hover. Check out this SCREENSHOT When hovering over the <a> sector, it's not showing the white image as expected. I have black and white icons, and I want the img src to ...

Is it truly impossible to align text around an image using flexbox?

In typical situations, you can easily float an image left or right to wrap text around it. However, in flexbox layouts, floating elements do not work as expected and finding a solution can be challenging. It is worth noting that Bootstrap 4 will be implem ...

What is the typical method for preserving a specific gap between two lines when the line spacing surpasses the margin?

My workplace provided me with a wireframe that looks like this: https://i.sstatic.net/Qumru.png Description of the image above: Maintain a margin of 10px between the lines and utilize the specified css class .font16. This is what the .font16 class conta ...

Enclose a text line within a flexible div container

I've encountered an issue with my CSS: I have a dynamic div containing a single line of text that needs to wrap every time the width of the div resizes to a smaller size. The challenge lies in having the text inside a table, serving as a directory fo ...

When viewing a page in IE 9 within a frame, not all CSS styles are properly rendered, causing it to enter Quirks mode

When a web page is loaded within a frame, not all of its styles are applied. The specific stylesheet used for the div elements is as follows: div.super{ position:absolute; font-family: Helvetica; font-size: 0.75em; padding:4px; overflo ...