我正在努力制作一个漂亮的下拉菜单。我搜索了一些教程和所有,我发现了一些好的。主菜单和第一个子菜单运行良好,但当鼠标悬停在第二个子菜单上时,第二个子菜单不显示。
这是我的html结构:
<body>
<ul class="menu">
<li><a href="#" class="home">Acceuil</a></li>
<li><a href="#" class="LoL">LoL</a>
<ul>
<li><a><span class="headlist">League of Legends</a></li>
<li><a href="#">Funny moments</a></li>
<li><a href="#">Favorite builds</a></li>
<li><a href="#">...</a></li>
</ul>
</li>
<li><a href="#" class="ssf2">SSF2</a></li>
<ul>
<li><a><span class="headlist">Super Smash Flash 2</a></li>
<li><a href="#">Intro</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Challenges</a></li>
</ul>
<li><a href="#">RotMG</a></li>
<li><a href="#">Videos</a></li>
<li><a href="#">Documents</a></li>
</ul>
</body>
这是我的CSS构建:
.menu,
.menu ul,
.menu li,
.menu a,
.menu p {
margin: 0;
padding: 0;
border: none;
outline: none;
}
/* Menu */
.menu {
height: 40px;
width: 610px;
background: #760101;
background: -moz-linear-gradient(#D20202, #760101);
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #760101),color-stop(1, #D20202));
background: -webkit-linear-gradient(#D20202, #760101);
background: -o-linear-gradient(#D20202, #760101);
background: -ms-linear-gradient(#D20202, #760101);
background: linear-gradient(#D20202, #760101);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 13px;
display: block;
margin-left: auto;
margin-right: auto;
}
.menu li {
position: relative;
list-style: none;
float: left;
display: block;
height: 40px;
}
.menu li a {
display: block;
padding: 0 7px 0 40px;
margin: 6px 0;
line-height: 28px;
text-decoration: none;
border-left: 1px solid #4B0101;
border-right: 1px solid #5C0101;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #f3f3f3;
text-shadow: 1px 1px 1px rgba(0,0,0,.6);
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
-o-transition: color .2s ease-in-out;
-ms-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
.menu li:first-child a { border-left: none; }
.menu li:last-child a{ border-right: none; }
.menu li:hover > a { color: #FF9900; }
/* Sub-menu */
.menu ul {
position: absolute;
top: 40px;
left: 0;
opacity: 0;
background: #D20202;
background: -moz-linear-gradient(#760101, #D20202);
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #D20202),color-stop(1, #760101));
background: -webkit-linear-gradient(#760101, #D20202);
background: -o-linear-gradient(#760101, #D20202);
background: -ms-linear-gradient(#760101, #D20202);
background: linear-gradient(#760101, #D20202);
-webkit-border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
border-radius: 0 0 5px 5px;
-webkit-transition: opacity .25s ease .1s;
-moz-transition: opacity .25s ease .1s;
-o-transition: opacity .25s ease .1s;
-ms-transition: opacity .25s ease .1s;
transition: opacity .25s ease .1s;
}
.menu li:hover > ul { opacity: 1; }
.menu ul li {
height: 0;
overflow: hidden;
padding: 0;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
.menu li:hover > ul li {
height: 36px;
overflow: visible;
padding: 0;
}
.menu ul li a {
width: 135px;
padding: 4px 0 4px 10px;
margin: 0;
border: none;
border-bottom: 1px solid #4B0101;
}
.menu ul li:last-child a {
border: none;
}
.LoL
{
background: url(LoLicon.png) no-repeat 6px center;
}
.home
{
background: url(home.png) no-repeat 6px center;
}
.ssf2
{
background: url(SSF2.png) no-repeat 6px center;
}
.headlist
{
color:#ff9900;
}
.menu ul li:first-child a {
border-bottom: 3px solid #4B0101;
}
欢迎回答!
答案 0 :(得分:1)
你在这里有错误:
<li><a href="#" class="ssf2">SSF2</a></li>
<ul>
<li><a><span class="headlist">Super Smash Flash 2</a></li>
<li><a href="#">Intro</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Challenges</a></li>
</ul>
它应该是:
<li><a href="#" class="ssf2">SSF2</a>
<ul>
<li><a><span class="headlist">Super Smash Flash 2</span></a></li>
<li><a href="#">Intro</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Challenges</a></li>
</ul>
</li>
这是一个working sample
答案 1 :(得分:0)
你必须把你的李包裹在子导航区。
你不能只是在ul中扔掉一个ul。
它是ul&gt; li> ul&gt;利
这是你问题的一部分。
编辑:此外,摆脱所有这些浏览器前缀。这些都是坏消息。几乎所有你想用CSS做的都很酷,所有现代浏览器都支持。也有例外。这个网站是你的朋友:http://caniuse.com/
如果浏览器不支持您正在做的事情,我的建议是让它在该浏览器中运行,但只要它看起来很棒 - 没有必要。他们有一个旧的/坏的浏览器。他们习惯于看起来不太棒的东西。