Issue with CSS: Dropdown menu is hidden behind carousel while hovering

I'm struggling with adjusting the position of my dropdown list. It keeps hiding behind the carousel (slider). When I set the position of the carousel section to absolute, it causes the navbar to become transparent and the images from the carousel show inside the navbar. I need assistance in resolving this issue.

Here is the code snippet where I am fetching navbar links from the database, so the links are dynamically generated in the navbar. Any suggestions for style improvements that could help resolve the issue would be appreciated.

function myFunction() {
     var x = document.getElementById("my-topnav");
     if (x.className === "top-nav") {
         x.className += " responsive";
     } else {
         x.className = "top-nav";
     }
 }
.top-nav {
  background-color: #f2f2f2;
  font-weight: bolder;
  overflow: hidden;
  position:relative;
  z-index:50;

}

.top-nav ul {
  padding: 0;
  margin: 0;
  list-style-type: none;
}



.top-nav .main a{
  display: block;
  text-align: center;
  padding: 14px 16px;
  color: #808080;
  text-decoration: none;
}
.top-nav .main .icon {
  display: none;
}
.top-nav .main li{
  display: inline-block;
  vertical-align: top;
  position: relative;

}

.top-nav .main > li > a{
  padding: 20px;
}

.top-nav .dropdown {
  position: absolute;
  background-color: #d9d9d9;
  width: 200px;
  left: 0;
  display: none;
}

.top-nav .dropdown ul{
  left: 200px;
}

.top-nav .dropdown li a{
  padding-top: 10px;
  padding-bottom: 10px;
}

.top-nav .dropdown li,
.top-nav .dropdown li
{
  display: block;
  width: 100%;
}

.top-nav ul li:hover .dropdown{
  display: block;
}

.top-nav .main li:hover > a{
  background-color: #4dc47d;
  color: white;
}

.top-nav .uni-name {
  text-transform: capitalize;
  font-weight: bolder;
  margin-right: 50px;
}
 //from navigation.php
<nav class="top-nav" id="my-topnav">
<ul class="main">
<li> <a href="../View/index.php" class="uni-name name-style">Abasyn University Islamabad Campus</a> </li>

<?= show_menu();  ?>

<li><a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a></li>

</ul>
 </nav>
 
//from the controller file

   while ($row = mysqli_fetch_assoc($result)) {
    # code...
      if ($row['page']) {
        # code...
        $menu .= '<li><a href="index.php?page_name=about&cat_id='.$row['cat_id'].'">'.$row['cat_title'].'</a>';

      }
      else {
        # code...
        $menu .= '<li><a href="index.php">'.$row['cat_title'].'</a>';

      }

      $menu .='<ul class="dropdown">'.generate_multilevel_menus($con,$row['cat_id']).'</ul>';

      $menu .='</li>';

  }

  return $menu;



Answer №1

To solve the issue of your dropdown menu hiding behind the carousel, you need to set a z-index for the dropdown element along with its absolute positioning. The z-index property controls the stacking order of positioned elements on a web page. Here is an example of how you can modify your CSS code:

.top-nav .dropdown {
  position: absolute;
  background-color: #d9d9d9;
  width: 200px;
  left: 0;
  display: none;
  z-index: 99999; /* Set a high value to bring the dropdown to the front */
}

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

Tips for inserting a PHP array into an email communication

I have a question regarding sending emails through PHP. How can I include PHP arrays in the message section of an email? Here is a simple array that I created and attempted to include in the email, but it seems incorrect as I couldn't find any releva ...

The request from localhost:3000 to localhost:3003 could not be proxied by ReactJS

Currently, I am working on developing a Single Page Application (SPA) using create-react-app with an expressjs server as the backend. During development, my frontend test server runs on port 3000 while my backend expressjs test server runs on port 3003. T ...

Utilizing the data sent to a modal to enhance the functionality of the code by combining it with the src attribute of an <embed> element

I am trying to pass a dynamic string of data to a Bootstrap modal using the data-val attribute in an HTML table. <td <button type="button" class="btn btn-success btn-xs" data-val="<?php echo $row['order_id']; ?&g ...

What is the best way to display a selected checkbox in an AJAX editing modal?

Can someone assist me in loading the checked checkboxes in an edit modal? I am using checkboxes to assign multiple roles in my system. Everything was working fine, but I encountered an issue with my edit modal where the checkboxes appear blank and unchecke ...

What is the best method for implementing Datepicker translations in Angular?

I am looking to incorporate the DatePicker component in Angular, enabling users to select a date that can be translated based on their browser's settings. Any suggestions on how to achieve this? <mat-form-field appearance="fill"> ...

Differences in Spacing: Exploring Bootstrap v5.1.1 Compared to 4.0

After comparing two pages, one using Bootstrap v5.1.1 and the other with 4.0.0, I have observed differences in spacing. Bootstrap v5.1.1: .topspacer { padding-top: 70px; } .righticon { float: right; } .clear { clear: both; } a { text- ...

`There is a delay in rendering the background image on Chrome`

Once I apply a class to my button element using JavaScript, the background image (.gif) that is supposed to display afterwards takes an unusually long time to render. The button serves as a form submission. Upon being clicked, a class of "clicked" is dyna ...

Executing the ES6 import syntax within a Node child process

After many attempts, I have come to the conclusion that I am ready to throw in the towel. My goal was to run a node es6 project that employs es6 import syntax; however, it seems that the child processes are not cooperating. The issue stems from the fact th ...

When using Vue.js router.push, the URL gets updated but the RankerDetail component does not refresh when navigating with a button

I am currently working on a Vue.js project that involves vue-router, and I've encountered an issue with the RankerDetail component. This particular component is responsible for dynamically displaying data based on the route parameter id. Strangely, wh ...

When defining multiple types for props in Vue, the default behavior for Boolean type props is not preserved

Imagine you have a component called MyComponent with a prop named myProp declared as: props: { myProp: Boolean } By simply using <MyComponent myProp/>, the default behavior would set myProp to true. However, this simplicity is lost when there ...

Issue with Tailwind classes not applying correctly upon refreshing the page in production settings

Challenge Description: Encountering an issue with my nextjs project that utilizes tailwindcss. The login page initially loads with the required classes for the UI, but upon refreshing the page, the classes disappear from the DOM, causing a broken UI. Her ...

Storing the result of an Angular $http.get request in a variable

As a newcomer to Angular, I am exploring how to retrieve a JSON object containing a list of individuals from CouchDB using a $http.get call. The JSON structure includes an id, names, and quotes for each person: { "total_rows": 2, "offset": 0, ...

Is there a way to deactivate the spin buttons for an input number field?

Is there a way to create an input element with type number in Vue using createElement() in TypeScript and then disable the spin buttons for increment and decrement? I attempted to use the following CSS: input[type=number]::-webkit-inner-spin-button, input ...

Issue in IE with click event not firing from parent page

Currently, I am facing an issue with a filter on one of my website's pages that is designed to display various products. My goal is to set it up so that when a button from an external page is clicked, the user will be redirected to the product page wh ...

What do you notice about interactions involving 'input type=text' in HTML and JavaScript?

When a new binding is created for the value property on an input, any manual modifications by the user no longer update the value. What happens when the binding is altered? Does regular user interaction involve key press listeners? I've modified the ...

Tips for safeguarding AJAX or javascript-based web applications

Utilizing AJAX, this function retrieves information about an image in the database with the ID of 219 when a button is clicked. Any visitor to this webpage has the ability to alter the JavaScript code by inspecting the source code. By modifying the code a ...

A comprehensive guide on implementing filtering in AngularJS arrays

I am working with the array provided below: [ { Id: 1, Name: "AI", Capacity: 2, From: "2021-10-27T08:00:00", To: "2021-10-27T08:50:00", }, { Id: 2, Name: "TEST", Capacity: 2, ...

What is the reason for min-content not being compatible with auto-fill or auto-fit?

My confusion lies in the fact that this code snippet works: .grid { display: grid; grid-template-columns: repeat(4, min-content); } Whereas this one does not: .grid { display: grid; grid-template-columns: repeat(auto-fill, min-content); } I am ...

When a specific condition is fulfilled, I must retrieve a random response from a designated array

I'm looking for a way to create a system where users can select multiple items and then generate a random answer from those selected options. Currently, I have a setup that requires manual input of options in a comma-separated format, but I want to st ...

Refreshing a component using a sibling component in React

Currently, I am delving into the realm of React and embarking on a journey to create a ToDo App. However, I've hit a snag while attempting to add a new task to the list. Despite successfully adding an item to the list upon clicking the add button, upd ...