M.Gooda M.Gooda - 7 months ago 12
HTML Question

CSS dropdown menue Navigation bar

I have a navigation bar with 5 elements. two of them have an additional dropdown menu, which should be displayed on mouse over. The problem is the background i make when mouse hover cover the tittle of the dropdown menue , and font color supposed to be white inside green background .

here are the html and CSS I have implemented:

<div class="nav">
<ul calss="main_ul">
<li><a href="#">Home</a></li>
<li><a href="#">HTML</a>
<ul>
<li><a href="#">choice 1</a></li>
<li><a href="#">choice 2</a></li>
<li><a href="#">choice 3</a></li>
</ul>
</li>
<li><a class="active" href="#">CSS</a></li>
<li><a href="#">Javascript</a>
<ul>
<li><a href="#">choice 1</a></li>
<li><a href="#">choice 2</a></li>
<li><a href="#">choice 3</a></li>
</ul>
</li>
<li><a href="#">jQuery</a></li>
</ul>
</div>


//and this is CSS:

.nav {
list-style: none;
margin: 0;
padding: 0;
position: relative;
text-align: left; /* change to "center" or "right" to align differently */
border-bottom: 10px solid green; /* bottom border */
background: #ffffff;
background: -moz-linear-gradient(top, #ffffff 0%, #d8d8d8 100%);
background: -webkit-gradient(linear, left top, left bottom, color- stop(0%,#ffffff), color-stop(100%,#d8d8d8));
background: -webkit-linear-gradient(top, #ffffff 0%,#d8d8d8 100%);
background: -o-linear-gradient(top, #ffffff 0%,#d8d8d8 100%);
background: -ms-linear-gradient(top, #ffffff 0%,#d8d8d8 100%);
background: linear-gradient(to bottom, #ffffff 0%,#d8d8d8 100%);
}
.nav ul li{
display: inline-block;vertical-align:top;
}
.nav ul a{
position: relative;
display: inline-block;
overflow: hidden;
color: black; /* font color */
text-decoration: none;
padding: 8px 20px;
font-size: 14px; /* font size */
font-weight: bold;
vertical-align: bottom;
-webkit-transition: color 0.5s; /* transition property and duration */
-moz-transition: color 0.5s;
transition: color 0.5s;
}

ul .nav a::before{
content: '';
color: white;
display: block;
position: absolute;
width: 100%;
height: 100%;
background: green; /* tab background */
left: 0;
top: 110%; /* extra 10% is to account for shadow dimension */
box-shadow: -2px 2px 10px rgba(255,255,255,.5) inset;
border-radius: 15px 15px 0 0 / 12px 12px;
-webkit-transition: top 0.5s; /* transition property and duration */
-moz-transition: top 0.5s;
transition: top 0.5s;
}

ul .nav a:hover{
color: white;
}
ul .nav a:hover::before{
top: 0; /* slide tab up */
}

.nav li ul {
position: absolute;
display: none;;
width: inherit;
margin:0px;
text-align:center;
}
ul li ul li a {
text-align:center;
}
.nav li:hover ul {
display: block;
}

.nav li ul li {
display: block;
}

Answer

A lot of your combinators are flipped. Change "ul .nav" wherever you see it to ".nav ul" and a lot of your issues will be fixed.

You may also need to changed the z-index of the background "tab"

Add to .nav:

z-index: 0;

add to the .nav ul a:hover::before:

z-index: -1;

https://jsfiddle.net/snfe8pvj/