我在如何对齐菜单和子菜单方面遇到了很多问题。我的子菜单出现在下一个菜单项上。 这是代码:
HTML
<div class="drsalnik">
<ul class="navbar">
<li><a href="Stranzaindexom.html" ><div class="item">Domov</div></a>
<ul>
<li><a href="Stranzaindexom.html" >Novice</a></li>
<li><a href="1stran-podstran1.html" >Akcije & popusti</a></li>
<li><a href="1stran-podstran2.html" >Najbolj iskano</a></li>
<li><a href="1stran-podstran3.html" >Fotografije tedna</a></li>
<li><a href="1stran-podstran4.html" >Foto-zgodbe</a></li>
<li><a href="1stran-podstran5.html" >Dostava</a></li>
</ul>
</li>
<li><a href="2stran.html" ><div class="item">Fotoaparati</div></a>
<ul>
<li><a href="2stran-podstran1.html" >DSLR</a></li>
<li><a href="2stran-podstran2.html" >Kompaktni</a></li>
<li><a href="2stran-podstran3.html" >Analogni</a></li>
<li><a href="2stran-podstran4.html" >Video kamere</a></li>
</ul>
</li>
<ul><a href="3stran.html" ><div class="item three">Objektivi</div></a></ul>
<ul><a href="4stran.html" ><div class="item four">Stojala</div></a></ul>
<ul><a href="5stran.html" ><div class="item five">Filtri in bliskavice</div></a></ul>
<ul><a href="6stran.html" ><div class="item six">Ostala oprema</div></a></ul>
</ul>
</div>
CSS
.drsalnik {
width:100%;
margin: auto;
overflow:hidden;
border: 0;
background-color: white;
}
.item {
height:40px;
width:16.5%;
float:left;
background-position: left top;
transition:width 0.5s ease;
font-size: 140%;
text-align: center;
border: black solid .5px;
opacity: 0.8;
}
.drsalnik:hover .item {
width:16.5%;
transition:width 0.5s ease;
opacity: 0.4;
}
.drsalnik .item:hover{
width:17.5%;
transition:width 0.5s ease;
background-position: center;
text-align: center;
opacity: 5;
}
.navbar{
list-style: none;
}
.navbar li{
display: block;
}
.navbar ul li{
opacity: 0.6;
padding-top: 5px;
}
.navbar li:hover {
opacity: 1;
display: block;
}
.navbar li:hover .item{
opacity: 1;
}
.navbar li ul{
display: none;
font-size: 110%;
margin-top: 40px;
background-color: white;
padding:10px;
font-style: italic;
position: relative;
float: left;
text-align: center;
}
.navbar li:hover ul{
display: inline;
position: absolute;
width: 14.5%;
}
所以我们的想法是让第一个菜单项的子菜单显示在下面而不是下一个菜单项下。我试图几乎在所有地方改变显示和位置,但似乎都没有。
这里的jsfiddle: http://jsfiddle.net/2mp6ajdx/
答案 0 :(得分:0)
请尝试将margin-left:-16.5%添加到.navbar li ul
.navbar li ul{
display: none;
font-size: 110%;
margin-top: 40px;
background-color: white;
padding:10px;
font-style: italic;
position: relative;
float: left;
text-align: center;
margin-left: -16.5%;
}