我有一个包含5个元素的导航栏。其中两个有一个额外的下拉菜单,应该在鼠标悬停时显示。问题是当鼠标悬停覆盖下拉菜单的标题并且字体颜色应该是绿色背景内的白色时我做的背景。
这里是我实现的html和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;
}
<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>
,
答案 0 :(得分:0)
你的很多组合器都被翻转了。改变&#34; ul .nav&#34;无论你在哪里看到它,都可以看到#。; .nav ul&#34;你的很多问题都将得到解决。
您可能还需要更改背景&#34;标签&#34;
的z-index添加到.nav:
z-index: 0;
添加到.nav ul a:hover :: before:
z-index: -1;