Challenges with positioning arise due to divs overlapping each other, preventing the accurate placement of the footer

My footer div is not sticking to the bottom of the page as I intended. Instead of remaining fixed at the bottom, it seems to be floating on top of the main content. Additionally, my divs are not lining up properly and appear to have padding on the top and bottom. Have I overlooked something in my markup?

Below is my HTML code:

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <title>The Frag Factory</title>
<div class="header">
    <div class="logo">
        <img src="includes/images/tffLogo.jpg"/>
    </div>
    <div class="nextLan">
        The Next LAN is on April 21-24th in
        </br><span>00d.00h.00m.00s</span>
    </div>
</div>
</head>
<body

<div class="navContainer">
    <ul>
        <li><a href="#">Events</a> |</li>
        <li><a href="#">Contact Us</a> |</li>
        <li><a href="#">Next Lan</a> |</li>
        <li><a href="#">Sponsers</a> |</li>
        <li><a href="#">Servers</a> |</li>
        <li><a href="#">Community</a></li>
    </ul>
</div>


<div class="container">
    <div class="sliderContainer">
        <img src="includes/images/sliderImage1.jpg"/>
    </div>
    <vertical around themdiv class="mainContainer">
        <h1>MAIN CONTENT</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempor, turpis faucibus ultrices mollis, nisl lectus fermentum orci, pulvinar vehicula neque metus vel leo. Praesent semper ullamcorper dolor, quis scelerisque neque venenatis quis. Vestibulum lacinia ut dolor ac fermentum. Pellentesque ornare facilisis ultrices. Donec vel purus eleifend, euismod metus in, faucibus sem. Nullam nulla odio, tristique sed velit vitae, pretium feugiat nibh. Sed a odio leo. Nullam eget enim pulvinar magna volutpat scelerisque eget nec est. Quisque sagittis tincidunt orci. Suspendisse ac erat ut turpis luctus euismod et eget dolor. Duis cursus, erat sed condimentum venenatis, purus urna sodales augue, vitae viverra purus augue sed tortor. Nullam adipiscing dapibus ultricies. In hac habitasse platea dictumst.</p>
    </div>
    <div class="sideBar">
        <center><img src="http://www.placehold.it/150x150"/>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempor, turpis faucibus ultrices mollis, nisl lectus fermentum orci, pulvinar vehicula neque metus vel leo. </p>
    </div>

</div>
<footer>
    <div id="footerContainer">
        THIS IS A FOOTER
    </div>
</footer>

</body>




</html>

Here is my CSS:

body{
    font-family: helvetica;
    letter-spacing: 0.09px;
    color: #717171;
    background-image: url("includes/images/dark_mosaic.png");
    display:block;
}
h1{}
h2{}
h3{}
p{}

.clear{
    clear:both;
}

/*HEADER*/
.header{
    width:900px;
    margin:0 auto;
    height:75px;
    background-color: #000;

}
.logo{
    float:left;
}
.logo img{
    height:70px;
    width:auto;
}
.nextLan{
    float:right;
    color:#36B627;
    text-align: center;
    padding-right:20px;
    padding-top: 6px;
}
.nextLan span{
    font-size: 40px;
    font-weight: bolder;
    vertical-align: center;
}

/*NAVIGATION*/
.navContainer{
    background-color: #535353;
    width:900px;
    height:25px;
    margin:0 auto;
    line-height: 25px;
    text-align:center;
    position: relative;
    top:-9px;


}
.navContainer li{
    display:inline;
}

/*SLIDER*/
.sliderContainer{
    width:900px;
    margin:0 auto;

}
.sliderContainer img{
    width:900px;
    height:auto;
}

/*MAINCONTENT*/


.container{
    width:900px;
margin:0 auto;
position: relative;


}
.mainContainer{
    width:680px;
    background-color: #000;
    float:left;
    padding:10px;
}
.sideBar{
    width:170px;
    background-color: #D66767;
    float:left;
    padding:10px;
    margin-left: 10px;
}
/*FOOTER*/

#footerContainer{
    position:absolute;
    height: 180px;
    clear:both;
    background-color: #fff;
    width:100%;
    padding:0;
    margin:0;
    left:0;

}

Answer №1

Let me consolidate my thoughts into an answer for you:

First and foremost, your HTML contains numerous validation errors. Placing <div> tags and content within the <head> section is incorrect. Content, including headers, should be placed within the <body> section. Reserve the <head> for meta information like <title>, any CSS links, scripts, etc. It appears that there are some unusual elements present in your code - such as a <font> tag which should be styled using CSS and not left unclosed. Furthermore, the line mentioning "vertical around themdiv" is nonsensical and not valid HTML. This seems to be a significant typo that may have been unintentionally included.

Next, it's important to ensure that your <br> tag usage is correct. It should either be simply <br> (for HTML5) or <br/> for XHTML. Avoid using </br> as this represents the closing version of the tag for HTML4.01 and older versions.

To address the issue with your footer placement, consider utilizing CSS Sticky Footer. The footer may not appear at the bottom of your content due to the use of position: absolute;, which removes the element from the normal flow of the document and fixes it at a specific position disregarding other elements nearby.

I've provided an updated solution on JSFiddle to assist you in resolving these major concerns. Note that unnecessary elements such as <!doctype>, <html>, and <head> are typically excluded from JSFiddle links.

Lastly, if you encounter empty CSS styles like p {} and h1 {}, it's best to remove them rather than keeping them blank. If needed, you can always add styling back to these elements later on.

Answer №2

After reviewing your HTML code, it's clear that there were several errors and invalid structures present. Rather than going into detail about each issue, I suggest checking out this demo for a visual representation.

The primary problem was that you needed to wrap everything except the footer in a container element, set its height to 100%, and adjust the margin-bottom to account for the footer height. Additionally, removing the absolute positioning from the footer was necessary.

I've spent more time refining a better solution for your layout woes. The updated approach ensures the footer stays at the bottom of the content without sticking to the bottom of the page itself. To achieve this, make both the html and body elements 100% in height, give the container a minimum height (to prevent issues when the page isn't maximized), and apply a negative top-margin on the footer matching its height. See the revised demo here in action along with the updated code below. Feel free to reach out if you have further queries.

HTML

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <title>The Frag Factory</title> 
</head>
<body>
   <!-- Code excluded for brevity -->
</body>
</html>

CSS

   /* CSS stylesheet omitted */

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 adjusting the right-hand edges of form elements when using percentage widths

Simply put, the issue is this: Why doesn't the second row of elements, with widths of 35% and 55%, take up the same amount of the page's width as the first form element which uses 90%? I often have to adjust the percentages differently dependin ...

Using CSS properties as false values within React applications

Can you provide guidance on using conditional styles with conditional operators? What would be the ideal code example? Is it possible to use non-CSS values? margin: isOpen ? '10px' : undefined margin: isOpen ? '10px' : 'initial&a ...

I'm facing an issue with the footer and header that is preventing me from properly positioning any content on the website

When attempting to include an h3 element on the website, it remains stuck at the top. I have tried using CSS properties like position, top, and left but it does not respond to them. Additionally, I experimented with a gallery template from w3schools to see ...

Is it possible to insert an image directly into the <img> tag without having to first send it to the server?

I've created an upload form that allows users to submit images: <form> <input accept="image/jpeg, image/gif, image/png" type="file" name="image" id="image" class="UploadInput" onchange="submitImageUploaderForm()"/> </form> Once t ...

How can you effectively load shared header and panel HTML onto pages located in separate directories using jQuery Mobile?

I am currently developing a multi-page application utilizing jQuery Mobile and incorporating loadPage() to retrieve various pages. The overall structure is outlined below. landing.html /app-pages/page1.html /app-pages/page2.html /app-pages/page3.html ...

Display a single image on the tablet and a distinct image on the computer

Currently, I am encountering an issue with my webpage located at . The problem lies in the right upper corner where a ribbon is located. However, when viewing the page on a tablet, the ribbon overlaps with my menu. To resolve this, I thought about displa ...

"An issue with the external jQuery file loop causes it to skip either the first or

I have a webpage where I am dynamically loading content from an external JavaScript file. This file identifies div elements with a specific class name and then fills the content of those divs based on a custom attribute, which contains a link to an API. Th ...

The close button on bootstrapselect is oversized

Having an issue with implementing the bootstrap select search and close button in my view. An image has been uploaded through the following link: View the bootstrap select dropdown image here Javascript $('#class_list_for_fee_report').multisel ...

When switching tabs in Javascript, the page does not automatically reload. However, the page will reload only when it is on

After writing a code using javascript/Youtube API + PHP to fetch a YT video ID from a MySQL server and place it in Javascript, I realized that the page only reloads when the tab is active and not when it's in the background. This issue disrupts the wh ...

Using onclick events, manipulating innerHTML, and dynamically generating tables

Below is the code snippet: window.onload=function(e){ //Created by Firestar001 var X; var Y; var board=""; var rizzalt=document.getElementById("rezzalt"); var letters = new Array; letters = ["A","B","C","D","E","F","G","H","I","J"]; for(a=0; a<=9 ...

Exploring the functionality of textareas within iframes on iPad

There is a known issue where textareas and inputs do not function properly on iPad Safari when placed inside an iframe. For more information, visit: This bug can easily be reproduced on iOS 7, but seems to work fine on iOS 8. Despite this issue, I am in ...

Guide to retrieving a user's current address in JSON format using Google API Key integrated into a CDN link

Setting the user's current location on my website has been a challenge. Using Java Script to obtain the geographical coordinates (longitude and latitude) was successful, but converting them into an address format proved tricky. My solution involved le ...

Delete the value from the array and refresh the HTML with the updated total amount, or display '$' if there is no total amount

Currently, I have two inputs: debit and credit. On button click events, they update an array called 'debits'. Debit adds positive values while credit adds negative values. The next step is to sum the values in the array and assign it to a variab ...

Is there a way to position the tooltip above the sorter icon in Ant Design (antd) component?

I'm currently working on creating a table with sorter columns using the antd framework. Can anyone guide me on how to position the tooltip above the sorter icon? Below is a snippet of my UI. https://i.sstatic.net/fGoqA.png Specifically, I included t ...

Ways to shorten a card

Below is a snippet of code that I have been working on. <div class="thim-course-grid"> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="lpr_course <?php echo ' ...

Transferring data from JavaScript to PHP for geolocation feature

Hello everyone, I'm looking to extract the longitude and latitude values from my JavaScript code and assign them to PHP variables $lat and $lng. This way, I can retrieve the city name and use it in my SQL query (query not provided). Below is the scrip ...

Automatic Textbox Closer

Connected to this AngularJS issue on IE10+ where textarea with placeholder causes "Invalid argument." and also this AngularJS 1.1.5 problem in Internet Explorer with ng-show and objects (Bug), we had to resort to using the textarea element as a self-closin ...

Using the symbols '&', '>', and '*' in the styling of React components

Below is the code snippet in question: const useStyles = makeStyles(theme => ({ row: { '& > *': { fontSize: 12, fontWeight: 'bold', color: 'rgba(33,34,34,0.5)', letterSpacing: 0.5, ...

Eliminate the header top margin in Bootstrap

HTML <div class="container-fluid"> <div class="row"> <div class="page-header header_site"> <h1><font>ABC Company</font></h1> </div> </div> </div> CSS Code: .header_site { b ...

Error Found in Angular2 Console Inspection

So, when I check the webpage inspection console, I see this error: Uncaught SyntaxError: Unexpected token { at Object.<anonymous> (main.bundle.js:3885) at __webpack_require__ (polyfills.bundle.js:51) at eval (eval at <anonymous> (m ...