Fixed position div (or sidebar) overlapping footer section

Issue: When making a specific div's position fixed (commonly used for sidebars or side menus), it overlaps with the footer when scrolling down.

body {
  margin: 0;
}
#header {
  width: 100%;
  height: 290px;
  background-color: #07CB6F;
}
#body {
  width: 100%;
  height: 3450px;
  background-color: #2FA3F7;
}
#body_inner {
  width: 1280px;
  height: 3450px;
  margin: 0 auto;
}
#side_menu {
  width: 220px;
  height: 270px;
  position: fixed;
  background-color: #ffffff;
}
#footer {
  width: 100%;
  height: 200px;
  background-color: #FF00AB;
}
<div id="header">
</div>
<div id="body">
  <div id="body_inner">
    <div id="side_menu"></div>
  </div>
</div>
<div id="footer">
</div>

This time, no jQuery is used. Despite setting #side_menu to height: 270px, the overlap still occurs when zooming in on the browser and based on different browsers and devices.

I am seeking insights into why this happens and how to address or prevent it from occurring.

Appreciate your assistance :)

Answer №1

Check out this solution in action

https://jsfiddle.net/stc0ogy2/1/

To resolve the issue, consider utilizing the z-index property. Similar to Photoshop layers, the z-index relies on defining a position like absolute or relative.

LATEST UPDATE

@AndreiGheorghiu suggested incorporating some javascript for an enhanced fix. Explore one of the plugins listed in his suggestions: list.

SECOND UPDATE

I stumbled upon a user-friendly library that could assist you with your fixed side menu, named tether. Give it a try!

Answer №2

Your website footer is set to expand to 100% of the width at the bottom, while a sidebar is intended to take up 220px of the space. However, on smaller screens, your menu and footer may compete for space since it's not feasible for one element to occupy 100% of the space while another sits beside it.

The issue may not be noticeable on full-screen desktops because the menu is too tall to cause any visible problems.

It's recommended to use `calc()` when defining the widths of the menu and footer to allow for resizing without overlap.

For a quick demonstration of how this works, you can check out https://jsfiddle.net/nu8av25m/.

<body>
    <div class="navigation">menu</div>
    <div class="main">main content</div>
    <footer>footer</footer>
</body>

.navigation {
    Width:50px;
    Height:100%;
    Background-color: red;
    Float:left
}

.main{
    Width: calc(100% - 200px);
    Height: calc(100% - 100px);
    Background-color: blue;
    Right:0;
}

Footer{
    Width: calc(100% - 100px);
    Height: 50px;
    Background-color:green;
    Bottom: 0
}

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

Is the footer missing from view?

I tried to replicate my header code for the footer, but it doesn't seem to be displaying. I've double-checked everything and can't figure out why it's not working. Maybe there is a typo somewhere. Below are the two sets of code: Heade ...

A guide on effectively utilizing ng-model within Angular.js

I am just starting to learn Angular.js and I am encountering an issue with my ng-model and ng-option. In my dropdown list, I have data that displays a code number along with the city name. I made some modifications to only show the city name without the nu ...

Creating an active tab using Material UI on a particular route

I've encountered an issue with Material UI tabs and need help figuring out how to resolve it. I have a navbar with three different tabs that link to separate URLs, but two of them are quite similar. Take a look at my code snippet below: <Tabs indic ...

The most effective method for removing harmful HTML tags and MySQL injections while maintaining the integrity of 'safe' tags in PHP

I need help filtering input HTML text from a webpage in the most effective way possible. I want to preserve text formatting while removing potentially dangerous tags such as script and iframe, all while ensuring protection against MySQL injections. For ex ...

Identifying mouse proximity through processing.js

I am using processing.js for coding. I am trying to dynamically adjust the size variable so that it increases as the cursor approaches the ellipse and decreases as the cursor moves away from it. I also want to set a limit for the size, preferably between 5 ...

Ensure consistency in CSS3 background color transitions

There are multiple elements on the webpage with background transitions that change from one color to another: @-moz-keyframes backgroundTransition /* Firefox */ { 0% {background-color:#ff7b7b;} 33% {background-color:#7fceff;} 66% {backgr ...

How can the selected value be shown in the dropdown menu after moving to a different webpage in HTML?

My application features 4 roles displayed in a dropdown menu. When a specific role is clicked, it should go to the corresponding href link that was specified. However, I encountered an issue where after navigating to the second HTML page, the selected rol ...

Troubleshooting: "alert() is not triggering for document functions"

I'm puzzled by a seemingly simple program that isn't running as expected. Here's the HTML code I'm using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml ...

"Trouble with Animations: Animate.css not functioning

I've been attempting to implement the animate.css plugin into my code, but for some reason, I just can't seem to get it working properly. Can anyone point out where I may have made a mistake? Here is the code I am using: <html> <head& ...

Ensure that the z-index of the div element is properly set

Here's the HTML code I'm working with: <div class="caption_center"> <h1 class="caption_header font-alpha">Making Your World More Comfortable</h1> <p class="caption_regular font-alpha">Let us convince you of that&l ...

Move column position within an HTML table

Can someone help me with this code snippet? <div class="row"> <div class="col-xs-12"> <div class="col-md-6"> <div class="col-sm-7"> Content B </div> <div class=& ...

The watermark feature in HTML may not appear when printed on every page

I'm facing an issue with adding a watermark style. The watermark displays only on the first page when attempting to print in Chrome. It works perfectly in Firefox and IE. <style type="text/css"> #watermark { color: #d0d0d0; font-size: 90pt; ...

Error: Unable to change image -- TypeError: Cannot assign value to null property 'src'

As I work my way through the textbook for one of my classes, I am practicing by building an image swapping page. The concept is simple - clicking on a thumbnail swaps out the main image and enlarges it as if it were linking to another web page. Despite fol ...

Maintaining Body Background Image Visibility While Adjusting Element Opacity/Transparency: A Complete Guide

As someone new to coding, I have a question for you all. This is the first time I haven't been able to find an answer online, perhaps due to my inability to effectively describe it. However, I have posted a picture to help illustrate my issue. I am l ...

Utilizing Jquery for deleting text content from a div element

I have a situation where I need to eliminate the text "(2012)" from a particular div using jQuery. Here is the code snippet that I am currently using: var el = $("#myDiv"); //replace(/word to remove/ig, ""); el.html(el.html().replace(/(2012)/ig, "")); ...

Maintaining the layout of blank lines in HTML content within JEditorPane

It has come to my attention that in an HTML JEditorPane, when there is an empty line, any previously applied styling disappears. Take a look at the code snippet below: import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.SwingUtil ...

Styling various versions of a <button> using Styled Components

In my app, I have a basic colored button that needs to change its color depending on the UI state: const StyledButton = styled.button` & { border: 0; color: white; cursor: pointer; } &:hover { background-color: ${(props) => ...

Conceal the Material UI Grid element and allow the following Grid Item to smoothly transition into its place

I need to create a form where certain Textfields must be hidden. However, when I attempt to hide a Grid item within a Grid container using display: none, the next grid item does not move to take its place. Instead, it creates whitespace. Is there a soluti ...

Video Autoplay within an image carousel - A seamless integration

I need assistance embedding a YouTube video as the fourth item in a slideshow on my website, www.serenitygardenrooms.com. The slideshow should play the first three images and then autoplay the video before moving on to the next image. However, the code sni ...

Disabling a button until the AngularJS http request is fully loaded: A step-by-step guide

When updating or submitting a form, I want the button to be disabled until the response from the server is complete. Similarly, during page loading, I need the button to remain disabled until all data has been loaded. Currently, in my code, the button rem ...