Position the div at the bottom of the menu container, ensuring it is not displayed on mobile devices

When I click the button on my mobile sidenav menu, it appears and disappears. I'm trying to figure out how to position

<div class="mtsMenu_footer">
at the bottom of the menu. I attempted to use position: absolute; and bottom: 0; in the CSS, which made the footer go down, but on mobile devices, the footer is not visible as it goes off the screen and appears lower than expected.

Edit: Thanks to AStombaugh's solution, I was able to resolve the issue by utilizing display: flex; and justify-content: space-between;. Additionally, I moved the footer div outside of the menu container to avoid any overlapping problems.

Here is an example of the JavaScript code for the sidebar menu:

// Sidebar Menu
var mobileMenu = document.querySelector(".btnmenu");
function openMenu(e) {
    e.stopPropagation();
    
    //Show & Hide Menu
    var x = document.getElementById("mtsMenu");
    x.classList.toggle("show");
    let toggle = document.querySelector('.btnmenu');
    toggle.classList.toggle("visible");
        
    //Show & Hide Overlay
    var y = document.getElementById("container_overlay");
    y.classList.toggle("on");
        
    //Prevent Page scroll with overflow
    var z = document.getElementsByTagName("body")[0]; 
    z.classList.toggle("ppscroll");
}

And here is an excerpt from the CSS styling:

<div onclick="openMenu(event)" class="btnmenu">Open Menu</div>
<div id="mtsMenu">
    <div class="mtsMenu_container"> 
        <!-- Menu items -->
    </div>
    <div class="mtsMenu_footer">
        <hr class="solid" />
        <span>THIS IS FOOTER CONTENT - THIS IS FOOTER CONTENT -THIS IS FOOTER CONTENT - THIS IS FOOTER CONTENT</span>
    </div>
  
</div>
<div id="container_overlay"></div>

Answer №1

It appears the issue lies in the usage of fixed, rather than absolute. When using absolute, the element will be positioned at the bottom with a value of 0, but its placement may vary based on screen size due to its absolute positioning behavior. Switching the footer to fixed resolves this problem by ensuring it remains visible consistently, not just within the menu.

To address this, I created a dedicated container for the footer to prevent interference with other HTML elements, sized accordingly with the menu. Placing the footer inside this container and utilizing fixed positioning resolved the visibility issue. Testing on my phone confirmed that the solution is effective.

In practice, considering potential overlap issues, implementing a media query @media might be necessary at some point. Nevertheless, the current resolution tackles the immediate concern.

// Sidebar Menu
var mobileMenu = document.querySelector(".btnmenu");

function openMenu(e) {
  e.stopPropagation();

  //Show & Hide Menu
  var x = document.getElementById("mtsMenu");
  x.classList.toggle("show");
  let toggle = document.querySelector('.btnmenu');
  toggle.classList.toggle("visible");

...
</pre>
<pre class="snippet-code-css lang-css"><code>/*Icon Button Menu*/

.btnmenu {
  display: flex;
  align-content: center;
  justify-content: center;
  align-items: center;
  width: 20%;
  color: #000;
  position: absolute;
  right: 0;
}

.btnmenu:before {
  font-family: fontAwesome;
  content: '\f0c9';
  float: right;
  z-index: 1000;
  font-size: 18px;
}

.btnmenu.visible:before {
  font-family: fontAwesome;
  content: '\f00d';
}
...
<div onclick="openMenu(event)" class="btnmenu">Open Menu</div>

<div id="mtsMenu">
  <div class="mtsMenu_container">
     ...
  </div>
  <div class="footerContainer">
    <div class="mtsMenu_footer">
      <hr class="solid" />
      <span>
          THIS IS FOOTER CONTENT - THIS IS FOOTER CONTENT
        </span>
    </div>
  </div>
</div>

<div id="container_overlay"></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

Press the button obscured by an image

Recently on my HTML website, I encountered an issue where I tried adding a transparent image over a button but found that I was unable to click on the button afterwards. The problem seems to be related to the following code snippet: #container { heigh ...

Steps For Adding Margins To A ProgressBar In Bootstrap To Give It A Spaced Look

Currently, I am endeavoring to design a progress bar that includes some spacing from the edges. The desired end result can be seen in the image below: https://i.sstatic.net/IvMFS.png The visual displays a red line within the gray progress bar, which is e ...

Issue with cancel button click in Jquery confirm window not being resolved

I have been encountering issues with opening a confirmation dialog in JavaScript despite having the code in place. The dialog is supposed to have 'yes' and 'no' options. function ConfirmDialog(obj, title, dialogText) { if (!dialogC ...

What is the best way to position a div as a footer within a larger main div?

I am aiming to create a div with simple header, content, and footer sections. Here is the design I am trying to achieve: https://i.stack.imgur.com/QfnGa.png You can check out my code on jsfiddle. I'm having trouble understanding how the relative lay ...

Restricting a checkbox to a maximum of 5 checkmarks

In a multi-column table, each column is represented by a checkmark. I want to limit the ability to tick a checkmark to only 5 checkmarks. Here is the code that has been implemented: <tbody> <ng-container *ngFor="let col of testData" ...

The content inside the bootstrap modal is not visible

My goal is to trigger a modal window when a specific div is clicked using bootstrap modal. However, upon clicking the div, the screen darkens but the modal body fails to appear. Code: <html> <head> <title></title> ...

Xpath: Determining the order of a tag in relation to text

Imagine there are two different snippets of HTML code as examples: <p>This is some text: <b>ABCD12345</b></p> <p><b>Name:</b> John Doe</p> I have the ability to separate the <b> and non-<b> sec ...

Incorporate pug and sass into your React project for a more

Are pug/jade and sass compatible with react? I enjoy organizing my code by separating files, and the functionality that sass and pug provide is great for this purpose. Is there a way to integrate pug and sass into a react project? Pug example: doctype ...

Combining two forms into one PHP page, but intending to submit only a single form

I'm facing an issue on my page where I have both a sign-in and a sign-up form. Whenever I click on either the sign-in or sign-up button, it always ends up submitting the sign-up form. What am I doing wrong? Here's the PHP code snippet: if($_SE ...

I'm looking to use JavaScript to dynamically generate multiple tabs based on the selected option in a dropdown menu

I'm reaching out with this question because my search for a clear answer or method has come up empty. Here's what I need help with: I've set up a dropdown titled 'Number of Chassis'. Depending on the selection made in this dropdown ...

What could be causing setInterval to only run once?

setInterval is only running once for me. I tried using setTimeout and creating a loop inside the function, but it's still giving the same output. I'm working with brackets and using live preview, in case that matters. const buttons = document. ...

Incorporating external libraries is seamless when used in a .html document, however, they may encounter limitations when integrated

I am facing an issue while migrating my code from an .html file to a Quasar project. The code runs perfectly fine in the .html file, but I encounter errors when implementing it in Quasar. Here is the original code from the index.html file: <!DOCTYPE ht ...

Is it possible to include jQuery's selectors contain and closest within my CSS selector?

I created a script to hide specific table rows as follows: $('.ms-formtable nobr:contains("Question")').closest('tr').hide(); However, I'm unsure if there is a way to achieve the same result using only CSS. Can anyone provide adv ...

What is the best way to incorporate both year and month filters using a dropdown menu on a traditional blog website?

I am currently working on a static blog article website and I am looking to implement a 'filter by year and month' feature. This will allow users to easily sort through blog articles based on their preferences. While I have successfully added a ...

Arrange objects to have identical beginning points

Here is how my html code is structured: <div class="text-center"> (bootstrap class) <p>Username</p> <p>Name:</p> <p>Last name:</p> <p>Email:</p> </div> Link to jsfiddle I am attempting ...

Guide to dynamically loading separate components on a single page in Angular 9

Rendering all components or widgets on the page at once can slow down the application's loading time. I prefer to have app-sidebar1, app-body, and app-sidebar2 load onto the DOM sequentially based on priority, rather than waiting for all components t ...

Html5 canvas not resizing to fit container

I'm currently working on creating a square canvas using CSS to ensure it is instantly sized when the page loads. To achieve this, I am wrapping the canvas in a div and applying the following styles: http://jsfiddle.net/evopgwzd/ body { backgrou ...

The function fromEvent is throwing an error stating that the property does not exist on the type 'Event'

I'm attempting to adjust the position of an element based on the cursor's location. Here is the code I am currently using: this.ngZone.runOutsideAngular(() => { fromEvent(window, 'mousemove').pipe( filter(() => this.hove ...

HTML 5 Video VTT File: A must-have for optimal video playback

Having trouble getting the subtitle.vtt file to load on Chrome with this code. Can anyone offer any insights? <div id="videoKilledTheRadioStar"> <video id="Tutorial" width="420" autoplay controls> <source src="videos/shaco.mp4" type="vi ...

Creating a persistent footer in a modal: A step-by-step guide

I'm currently working on a react-modal that slides in from the bottom of the screen with an animated effect. The challenge I am facing is getting the footer of the modal to stay fixed at the bottom of the browser window. Despite using the standard CSS ...