Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make dropdown in html overlap another div

Tags:

html

css

So I got a navigation bar and some of the items there are having a dropdown menu when you hover over them. Right below the nav bar, there is a slideshow of images. The problem is that everytime I hover on the dropdowns, The slideshow div gets in the way so the dropdown menu cant be seen. enter image description here

i have the ff html code

  <div class="dropdown">
      <li class="dropbtn">About Us</li>
      <div class="dropdown-content">
        <a href="#"> Overview and History</a>
        <a href="#">Vision</a>
        <a href="#">Objectives</a>
        <a href="#">Organization</a>
        <a href="#">About NEU</a>
      </div>
    </div>

and the css

    .dropbtn {
background-color: inherit;
color: black;
padding: 12px;
font-size: 20px;
border: none;
cursor: pointer;
}

.dropdown {
position: relative;
display: inline-block;
margin: 0;
padding: 0px;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
display: block;
}

.dropdown:hover .dropbtn {
background-color:  #0099ff;
}
like image 989
SoulRider Avatar asked Mar 11 '23 22:03

SoulRider


2 Answers

You can use z-index attribute as it specifies the stack order of an element.

An element with greater stack order is always in front of an element with a lower stack order.

Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).

Example:

<!DOCTYPE html>
<html>
<head>
<style>
img {
    position: absolute;
    left: 0px;
    top: 0px;
    z-index: -1;
}
</style>
</head>
<body>

<h1>This is a heading</h1>

<img src="w3css.gif" width="100" height="140">

<p>Because the image has a z-index of -1, it will be placed behind the text.</p>

</body>
</html>

For more information : Check out here

like image 71
Cristofor Avatar answered Mar 19 '23 16:03

Cristofor


add z-index to .dropdown

.dropdown{
   z-index: 999;
}
like image 32
Rahul Avatar answered Mar 19 '23 18:03

Rahul