SoulRider
SoulRider

Reputation: 155

How to make dropdown in html overlap another div

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;
}

Upvotes: 4

Views: 23560

Answers (6)

Herbs
Herbs

Reputation: 146

Add the z-index property to .dropdown-content

.dropdown-content{
   z-index: 1000;
}

Upvotes: 1

Cristofor
Cristofor

Reputation: 2097

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

Upvotes: 5

kind user
kind user

Reputation: 41893

You have to pull the div up to the surface by using the z-index property.

.dropdown {
  z-index: 99;
}

Upvotes: 1

Bhavin Shah
Bhavin Shah

Reputation: 2482

Use z-index.

.img_div{z-index:999;}
.drop_down_div{z-index:1001;}

Upvotes: 0

Rahul.A.Krishna
Rahul.A.Krishna

Reputation: 98

Increase the z-index of .dropdown-content. Put some value like 2

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

That should help!

Upvotes: 1

Rahul
Rahul

Reputation: 4364

add z-index to .dropdown

.dropdown{
   z-index: 999;
}

Upvotes: 1

Related Questions