Is there a way to position the menu above the button?

I need some help with my menu. Currently, it is showing up below the button and within my footer instead of above the content like I want it to. If anyone can assist me in understanding what I am doing wrong, I would greatly appreciate it. Thank you for taking the time to help.

This is the code for my button and menu. If you have any advice or suggestions on how to fix this issue, I would be very grateful. Thank you for your time.

document.addEventListener('DOMContentLoaded', function() {
    const toggleButton = document.getElementById('menu-toggle');
    const menu = document.querySelector('.ja-menu');

    // Initially hide the menu
    menu.style.display = 'none';

    toggleButton.addEventListener('click', function() {
        // Toggle menu visibility
        if (menu.style.display === 'none') {
            menu.style.display = 'block';
        } else {
            menu.style.display = 'none';
        }
    });
});
.ja-menu {
    width: 154.5px;
    height: 238px;
    background: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    padding: 0; /* Remove padding here and let .j-menu-item handle it */
    border-radius: 10px;
    box-sizing: border-box;
}

    .ja-menu-item {
    display: block;
    padding: 10px;
    justify-content: center;
    text-decoration: none;
    transition: background 0.3s;
    ont-size: 14px;
    font-family: arial, sans-serif;
    color: #202124;
    box-sizing: border-box;
    
}
    .ja-menu-item-text {
    text-align: left; /* Align the text to the left */
}


.ja-menu-item:hover {
    background: #DADCE0;
}

.ja-divider {
    height: 1px;
    background-color: #DADCE0;
    margin: 0; /* This ensures the divider does not extend into the padding area */
}

.ja-toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px; /* Maintain consistent padding with .j-menu-item */
}

.ja-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.ja-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.ja-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.ja-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.ja-switch input:checked + .j-slider {
    background-color: #2196F3;
}

.ja-switch input:focus + .j-slider {
    box-shadow: 0 0 1px #2196F3;
}

.ja-switch input:checked + .j-slider:before {
    transform: translateX(26px);
}
<div id="menu-container" style="position: relative; display: inline-block;">
                        <a id="menu-toggle" class="pHiOh" href="javascript:void(0);">Settings</a><div class="j-menu">

    <div class="ja-menu">
    <a class="ja-menu-item" href="#">Search settings</a>
    <a class="ja-menu-item" href="#">Advanced search</a>
    <a class="ja-menu-item" href="#">Your data in Search</a>
    <a class="ja-menu-item" href="#">Search history</a>
    <a class="ja-menu-item" href="#">Search help</a>
    <a class="ja-menu-item" href="#">Send feedback</a>
     <div class="ja-divider"></div>
    <div class="ja-menu-item ja-toggle-container">
        <span>Dark theme:</span>
        <label class="ja-switch">
            <input type="checkbox" id="j-dark-theme-toggle">
            <span class="ja-slider round"></span>
        </label>
    </div>
</div>

Answer №1

Apply this specific inline style to the ja-menu element:

<div class="ja-menu" style="position: absolute; bottom: 100%;">

document.addEventListener('DOMContentLoaded', function() {
  const toggleButton = document.getElementById('menu-toggle');
  const menu = document.querySelector('.ja-menu');

  // Initially hide the menu
  menu.style.display = 'none';

  toggleButton.addEventListener('click', function() {
    // Toggle menu visibility
    if (menu.style.display === 'none') {
      menu.style.display = 'block';
    } else {
      menu.style.display = 'none';
    }
  });
});
<style>.ja-menu {
  width: 154.5px;
  height: 238px;
  background: #fff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  padding: 0;
  border-radius: 10px;
  box-sizing: border-box;
}
.ja-menu-item {
  display: block;
  padding: 10px;
  justify-content: center;
  text-decoration: none;
  transition: background 0.3s;
  font-size: 14px;
  font-family: arial, sans-serif;
  color: #202124;
  box-sizing: border-box;
}
.ja-menu-item-text {
  text-align: left;
}
.ja-menu-item:hover {
  background: #DADCE0;
}
.ja-divider {
  height: 1px;
  background-color: #DADCE0;
  margin: 0;
}
.ja-toggle-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
}
.ja-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}
.ja-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.ja-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 24px;
}
.ja-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}
.ja-switch input:checked+.j-slider {
  background-color: #2196F3;
}
.ja-switch input:focus+.j-slider {
  box-shadow: 0 0 1px #2196F3;
}
.ja-switch input:checked+.j-slider:before {
  transform: translateX(26px);
}
#menu-toggle{
  border: 1px solid;
  padding: 8px;
  color: white;
  background-color: darkcyan;
  border-radius: 5px;
  text-decoration: none;
  font-size: 20px;
}
<div style="margin-top: 500px"></div>
<div id="menu-container" style="position: relative; display: inline-block;">
  <a id="menu-toggle" class="pHiOh" href="javascript:void(0);">Settings</a>
  <div class="j-menu">
    <div class="ja-menu" style="position: absolute; bottom: 100%;">
      <a class="ja-menu-item" href="#">Search settings</a>
      <a class="ja-menu-item" href="#">Advanced search</a>
      <a class="ja-menu-item" href="#">Your data in Search</a>
      <a class="ja-menu-item" href="#">Search history</a>
      <a class="ja-menu-item" href="#">Search help</a>
      <a class="ja-menu-item" href="#">Send feedback</a>
      <div class="ja-divider"></div>
      <div class="ja-menu-item ja-toggle-container">
        <span>Dark theme:</span>
        <label class="ja-switch">
          <input type="checkbox" id="j-dark-theme-toggle">
          <span class="ja-slider round"></span>
        </label>
      </div>
    </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

Filtering an array by a search term

How do you filter an array based on a specific search term? For example, if we have an array [Tom Harry, Tom John, John Glen, Tom Harward] and we search for "Tom H," then only Tom Harry and Tom Harward should be the output. [Tom Harward, Tom Harry]; Usin ...

Understanding the syntax for matching files and paths in Node/JavaScript using glob, including the use of wild

I stumbled upon http://gruntjs.com/configuring-tasks#globbing-patterns and found it to be the most useful reference so far. I have come across the following statement multiple times: For more on glob pattern syntax, see the node-glob and minimatch docu ...

Error: Issue determining the type of variable. Unable to eliminate type 'any'

I am trying to load some widgets from a template object (possibly JSON in the future). Here's an example: type RectangleTemplate = { name: 'Rectangle'; props: { width: number; height: number; } }; type ButtonTemplate = { nam ...

Elevate a division within its container

Is there a way to make a smaller div positioned at the top when it's placed next to a larger one in the same container? I'm looking for a solution that doesn't involve using position-relative and manually adjusting the placement. Take a loo ...

Guide to aligning a component in the middle of the screen - Angular

As I delve into my project using Angular, I find myself unsure about the best approach to rendering a component within the main component. Check out the repository: https://github.com/jrsbaum/crud-angular See the demo here: Login credentials: Email: [e ...

Here are the steps to trigger a pop-up window in JavaScript that is filled with data fetched via an AJAX call:

I'm currently working on a java class where I need to insert a link into a table grid. This code is specific to the internal API of our company. /***MyCustomLink.java*********/ customLink.setOnClick( "fetchURL", return false;); addGridItem("cu ...

I am unable to locate the appropriate TypeScript type for the `displayName` attribute when it is used as a prop for the `type` component

Having trouble finding the correct type as mentioned in the title. After inspecting with DevTools, I have confirmed that every component I am programmatically looking at has Component.type.displayName. For anything that is not an ElementType, the type is a ...

Switching button appearance when hovered over

Looking to create a page layout with 4 buttons, each occupying one quadrant of the page? These buttons should feature images as their background and change to different images when hovered over. Wondering how this can be achieved using CSS? ...

Using AngularJS to iterate through JSON data

I received JSON data from my Facebook account and saved it in a file called facebook.json. Next step is to retrieve and process the data from the JSON file in my controller. app.controller('Ctrl', function($scope, $http) { $http({metho ...

Animate CSS every quarter of a minute

Is it possible to create an animation that runs infinitely every 15 seconds in the sequence 1, 2, 3, 4, 3, 2, 1 with different delays for each item using CSS? The animation delay seems to only work on the first iteration. Achieving this effect is easy wi ...

The act of exporting an enum from a user-defined TypeScript path leads to the error message "Module not

I have set up a custom path as explained in this particular discussion. "baseUrl": ".", "paths": { "@library/*": [ "./src/myFolder/*" ], } Within this module, I am exporting an Enum. export enum EN ...

encountering issue alerts when using the MUI TextField module alongside the select function

Encountering an error in the MUI console: children must be provided when using the TextField component with select. <TextField select id="outlined-basic" label="User Name" name="user" size="small" {...teamForm.getFieldProps("user")} erro ...

A guide on retrieving information from a database with PHP and transferring it to Javascript

As I work on creating a website using HTML, CSS, MySQL, and JavaScript, my goal is to allow users to log in and engage in a quiz with 40 questions. Below is the JavaScript code for a countdown timer that includes the "questions" variable. After 40 seconds ...

Leveraging jQuery within a method defined in an object using MyObject.prototype.method and the 'this' keyword

Recently, I've started exploring Object-oriented programming in JavaScript and have encountered a challenge. I'm trying to define an object like the example below, where I am using jQuery inside one of the methods. I'm curious about the best ...

How can PHP be used to replace the div html() function?

I am working with multiple product elements that are dynamically assigned their class and ID using PHP: $product1["codename"] = "product-1"; $product1["short"] = "Great Product 1"; $product2["codename"] = "product-2"; $product2["short"] = "Great Product ...

Encounter a parameter validation error

Just a quick question. I have a JS function that takes a parameter as input. If the passed value happens to be NULL, I want to handle it accordingly. However, my limited experience with JS is making it difficult for me to use the correct syntax. Here' ...

unable to locate the font file I recently downloaded in the Windows terminal

Interested in customizing your Windows terminal? I recently decided to change my font style and downloaded the desired one. However, despite seeing the font in control panel and trying the "downloading for every user" option, my terminal still can't l ...

What is the method to obtain an object as the return value from a click function in JavaScript?

I would like to retrieve the cell value from a table by clicking on a button. I have already created a function called getDetail in JavaScript that is implemented on the button, but I am facing difficulty in returning the value from the function. <butto ...

Identify a CSS style or attribute that is being dynamically assigned using JavaScript

While using the Jquery Cycle plugin for my slideshow, I'm looking to trigger an event when a specific slide is active. The Cycle plugin handles this by adjusting the opacity of images within a div in this manner: <div style="position: absolute; to ...

I can't seem to figure out the source of this unexpected padding/margin on my website

After creating a website for a church using Foundation, SASS, and Compass, I noticed a horizontal scroll issue when resizing the window. Adding overflow-x: hidden; seemed to fix it, but there was still about 20px of padding on the right side when testing ...