The layout of the website is styled using CSS, with the footer positioned halfway up

I require assistance to resolve an issue in my CSS layout. The footer is currently positioned midway up the contents instead of being placed right below. You can view my code below. Please help me, as I'm not sure what went wrong and have already invested a lot of time into this.

HTML:

    <title>My Reporting System</title>
    <link rel="stylesheet" type="text/css" href="style.css" />    
<body>
    <div id="user-logged">
        You are logged in as : <strong>User</strong><br>Logout
    </div>
    <hr>
    <div>
        <a id="logo" href=".">
            <img id="logo" src="images/logo.png" alt="BRS"/>
        </a>
        <div id="sidebar"> 
           
                My Reporting System
            
            <ul>
                <li>Outlet Settings</li>
                <li>Update Daily Stats</li>
                <li>Void Stats</li>
                <li>Email Report</li>
            </ul>
        </div>
    </div>
    <div class="body-content">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam  
    pharetra eget lacus vitae elementum. Morbi a justo est. Aenean aliquet    
    elit ac nunc vestibulum rutrum. Vestibulum blandit pellentesque erat, a 
    imperdiet sem. In egestas in sapien at pelle...

css:

#logo {
    position:absolute;
    top:5px;
    left:15px; 
    width:150px;
    height:auto;
}
#sidebar {      
    width:200px;
    min-height:500px;
    height:auto;    
    background-color: #6699cc;
    padding:1px;
}
#user-logged {
    top:0px;
    right:0px;
    text-align: right;
    padding-top:50px;
    padding-right:10px;
    margin-left:200px;
    height:50px;
    min-width:200px;
}
.body-content {
    position:absolute; 
    top:126px;
    margin-left:202px;
    min-height:700px;
    background-color: #ccc;   
    width:80%;
    clear:both;
    height: auto !important;
}
#footer {
    position:absolute;
    padding-top:20px;
    width:100%;
    height:150px;
    font-size:12px;
    background-color: #cc9966;
    text-align:center;
    font-weight:bold;
    color:#fff;
}

Answer №1

The problem you are experiencing is due to the way you have applied absolute positioning to your .body-content div. When a div is positioned absolutely, it is essentially taken out of the normal document flow, causing the footer to position itself in an unexpected manner. I have made some adjustments here that demonstrate how using floats instead of absolute positioning can solve this issue.

The changes involve floating both the sidebar and .body-content, eliminating the clear: both property from .body-content, and adjusting the width of .body-content. There may be additional tweaks required, but these steps should give you a good starting point.

(If absolute positioning is necessary for your layout, alternative approaches may need to be considered.)

#logo {
  position: absolute;
  top: 5px;
  left: 15px;
  width: 150px;
  height: auto;
}
#sidebar {
  width: 200px;
  min-height: 500px;
  height: auto;
  background-color: #6699cc;
  padding: 1px;
  float: left;
}
#user-logged {
  top: 0px;
  right: 0px;
  text-align: right;
  padding-top: 50px;
  padding-right: 10px;
  margin-left: 200px;
  height: 50px;
  min-width: 200px;
}
.body-content {
  float: left;
  min-height: 700px;
  background-color: #ccc;
  width: 65%;
  height: auto !important;
}
#footer {
  clear: both;
  padding-top: 20px;
  width: 100%;
  height: 150px;
  font-size: 12px;
  background-color: #cc9966;
  text-align: center;
  font-weight: bold;
  color: #fff;
}
<div id="user-logged">
  You are logged in as : <strong>User</strong>
  <br>Logout

</div>
<hr>



<div>
  <a id="logo" href=".">
    <img id="logo" src="images/logo.png" alt="BRS" />
  </a>
  <div id="sidebar">

    <h1 style="color:#fff; padding-left:20px; font-size:15px;">My 
    Reporting System</h1>


    <ul>
      <li>Outlet Settings</li>
      <li>Update Daily Stats</li>
      <li>Void Stats</li>
      <li>Email Report</li>
    </ul>
  </div>
</div>


<div class="body-content">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam pharetra eget lacus vitae elementum. Morbi a justo est. Aenean aliquet elit ac nunc vestibulum rutrum. Vestibulum blandit pellentesque erat, a imperdiet sem. In egestas in sapien at pellentesque.
  Praesent non commodo nunc. Integer porta malesuada placerat. Maecenas nec sem varius, suscipit sem vitae, vulputate ligula. Nam sed ligula suscipit, faucibus augue et, iaculis nibh. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
  ridiculus mus. Nam at neque vel est elementum tincidunt. Nullam accumsan finibus mauris, non auctor enim. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Ut at ligula eu turpis volutpat aliquet et et quam. Aliquam
  est nulla, eleifend eu nibh a, lobortis mollis ex. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed cursus, dui eu finibus ultricies, leo velit laoreet sapien, in pretium lectus ipsum quis turpis. Ut ornare
  nulla eu facilisis condimentum. Etiam venenatis tellus et lorem dapibus, et vestibulum mauris facilisis. Etiam quis feugiat orci, sit amet blandit nisl. Phasellus feugiat auctor vehicula. Quisque congue enim leo, nec sagittis sem tincidunt vitae. In
  in tellus lacus. Aenean porta ligula sed est bibendum, sed tincidunt eros pellentesque. Suspendisse potenti. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur vitae lacus a justo tempor semper nec eu nisl. In a odio feugiat, mattis
  urna eu, efficitur risus. Aliquam laoreet a magna vitae convallis. Quisque vehicula urna sit amet nisl faucibus facilisis. Quisque velit arcu, pre...
  
<div id="footer">
  Test 2015. All rights reserved.
</div>

Answer №2

resolution: Update sidebar to have position: fixed Adjust body-content to have position: static Eliminate top 126px from body-content Huge shoutout to Mr. Cory for the guidance.

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

Margin not being applied to last element in parent - any ideas why?

Why does the margin of the last element, whether it is a <p> or <h1>, not have any impact? It should be pushing the background of the parent container downwards. .container { background: grey; } h1 { margin-bottom: 3em } p { margin- ...

How to Align a Button in the Middle with Bootstrap?

Hey there! I'm working on creating a video list. I've utilized the bootstrap grid system to put it together. Here's the code I have so far: I'm trying to center the play button both vertically and horizontally within the thumbnail. Any ...

How to integrate Phpfox::getBlock into a template file within PHPFOX

Today, I attempted to integrate Phpfox::getBlock into the template file within PHPfox but encountered some issues. Can someone take a look and identify where the problem lies? I am looking to include a PHP block: core.template-copyright into the followi ...

Is it possible to modify a single entry in a series of records?

I have a list of data entries, such as addresses, and I am currently displaying them using the following combination of html5 and knockout code. <section id="lists" data-bind="foreach: addresses, visible: addresses().length > 0"> <article& ...

Modifying the overflow behavior within a Vuetify dialog

Is there a way to have a floating action button positioned on the top right of a dialog, slightly overflowing so it's offset from the dialog itself? I'm struggling to override the 'overflow-y: hidden' property set by v-dialog. <v-dia ...

Which names can be used for HTML form tags in jQuery?

Recently, I encountered an issue related to jQuery form serialization which stemmed from naming a form tag "elements". The problem arose when using jQuery $(’form’).serialize(). Here is an example of the problematic code: <form> <input name=" ...

Having trouble executing a JavaScript function correctly when using an onclick event created within innerHTML in JavaScript

My goal is to trigger the loadInWhat function with an onclick event and populate my input field with id="what" using the value of LI function createDivBox(data){ document.getElementById("whatContainer").style.display="block"; document.get ...

Implementing mobile view padding using CSS

Recently, I encountered a dilemma with a code snippet in my project. When viewed on mobile devices, the square boxes within the design would horizontally scroll. Below are the CSS snippets responsible for this behavior: @media only screen and (max-width: ...

Add a pair of assorted div elements to a shared container

I have two different sections with classes named "red" and "blue". By default, these sections are hidden. I want to duplicate them and display them in a single container named "cont". The red button appends the red section and the blue button appends the b ...

Any ideas on how to fix the error that pops up during the installation of the bootstrap package in Node

The npm command is not recognized as a valid cmdlet, function, script file, or operable program. Please double check the spelling of the command and ensure that the path is correct before trying again. This error occurred at line 1. npm i bootstrap + ...

Secure access to an API using a certificate within a Vue.js application running on localhost

My vue.js app is built using vue-cli. The application is hosted at dev.example.com and the REST API can be found at dev.example.com/api/v1/. The backend has added an SSL certificate for security on the development environment. However, when I try to make a ...

Is there a way to activate the final form when submitted?

I am facing an issue with React Final Form. Despite following the example in the official documentation, I am still struggling to understand why my form is not triggering the onSubmit function as in the example. I am also grappling with understanding the p ...

When attempting to upload a file from IOS10.3.1, the server received the correct file size but retrieved incorrect data, all of which appeared as

I'm facing issues with correctly uploading files. Our iOS and Android app allow users to select a local image file and upload it to our Nginx server. Issue Summary: Approximately 5% of the total upload requests result in broken image files on the se ...

Issue with code displaying boxes according to selected radio checkboxes

I stumbled upon this Code Snippet, but for some reason, I can't seem to make it work on my website or even on a simple test page. I'm not sure what I'm overlooking? Check out the JS Fiddle: http://jsfiddle.net/technologrich/tT48f/4/ I&apos ...

Navigate to a different page after completing form submission

I am facing an issue with navigating between pages on my website. I have a form that processes data upon submission, and after processing, I want to redirect the user back to the previous page. Currently, my webpage consists of a list of links that lead to ...

Safari is having trouble correctly displaying a CSS3 gradient with transparency

Here's a tricky puzzle for you. The gradient below is not displaying correctly in Safari, but it works perfectly fine in Firefox and Chrome: background: linear-gradient(transparent 124px, #de6230); I've even attempted the following fix without ...

What is the method for showcasing login errors and prompting users to fill in all fields simultaneously on a page with PHP?

As I develop a PHP login page, I am implementing a system where users need to enter a username and password to access the platform. One query that arises is: How can I dynamically display an 'Invalid username or password' error message on the s ...

Tips for changing and resetting a background-color property after a hover effect

Is it possible to remove the background-color property of a :hover rule? I have a set of elements that change color when hovered over. I want to add another CSS rule to prevent this color change. Here's an example: http://jsfiddle.net/vqLuU/1/ How ...

Tips for extracting text based on an id

Is there a way to continuously scrape a website every second and display the results, given that all it currently seems to print is '[]'? I've attempted using both id and class identifiers without success. Additionally, the text being scrape ...

"Div does not perfectly match the height of its parent div when using the 'inherit' value

I have 3 divs inside a parent div, intended to be arranged like so: ______________________________________ | | | HEADER | |______________________________________| ____ ________________ ...