无法使菜单栏下拉正常悬停 [英] Cannot make menubar dropdown hover properly
问题描述
我有一个菜单栏,它有8到9个水平不同字符长度的菜单。
此外,每个菜单都有不同字符长度的子菜单。
I have a menu bar which has 8 to 9 menus horizontally of different character length. Also, each and every menu has sub menus of different character length.
我想要的是 -
1.所有菜单页面(应该填充我决定的html体宽度)
2.所有的子菜单应该是下拉的,并且宽度与父菜单宽度相同。
All I want is - 1. all the menus should be across the page (should fill the html body width that i have decided) 2. all the sub menus should be drop down and will be of same width like as the parent menu width.
我可以做的是,我有拉伸的菜单栏,以便它可以填充html体宽度,他们采取对称宽度。但我不能使子菜单一个接一个地下降。
我也参加了我想要的示例图片
All i can do is, i have stretched menu bar so that it can fill the html body width and they took symmetrical width. but i cannot make the sub menus to be drop down one after another. I have also attched examplary pictures of what i want
HTML
HTML
<div id="header_menu">
<ul >
<li><a href="#">Product Repository </a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">File Upload</a></li>
</ul>
</li>
<li><a href="#">Inventory Inspection</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">Reprint</a></li>
<li><a href="#">Inventory Report</a></li>
</ul>
</li>
<li><a href="#">Reports</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
</ul>
</li>
</ul>
</div>
CSS
CSS
body
{
width: 80%;
margin-left: auto;
margin-right: auto;
text-align:center;
}
我为我提供工作的CSS。希望
其他别人。
HTML is already provided. i'm providing the working CSS for me. hope it else somebody else.
#header_menu {
height: 10%;
margin-bottom: 2px;
width: 100%;
}
#header_menu ul li ul {
position: absolute;
float: left;
}
#header_menu ul {
margin: 0px;
padding: 0px;
list-style-type: none;
display: table;
width: 100%;
height: 10%;
position: relative;
z-index: 597;
}
#header_menu ul li ul li a {
visibility: hidden;
height: 0px;
width: 100%;
}
#header_menu ul li:hover ul li a {
height: 10%;
visibility: visible;
width: 100%;
}
#header_menu ul li {
position: relative;
display: table-cell;
list-style-type: none;
}
#header_menu ul li a {
display: block;
color: #FFF;
text-decoration: none;
background-color: #333;
font-family: Meiryo, "Meiryo UI", "Microsoft Sans Serif", "MS Outlook";
font-weight: lighter;
font-size: 12px;
border-right-width: thin;
border-bottom-width: thin;
border-right-style: inset;
border-bottom-style: inset;
border-right-color: #999;
border-bottom-color: #999;
}
#header_menu ul li ul li {
width: 100%;
float: left;
}
#header_menu ul li a:hover {
font-family: Meiryo, "Meiryo UI", "Microsoft Sans Serif", "MS Outlook";
font-size: 12px;
font-weight: lighter;
background-color: #000;
}
推荐答案
有 jsfiddle示例来自 CSS Menu Maker网站
我做了一些小改动以简化示例。
I made some little changes to simplify example. Little update, nothing special
更新(fiddle too):
$ b
Update (fiddle too):
<div id='cssmenu'>
<ul>
<li><a href="#">Product Repository </a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">File Upload</a></li>
</ul>
</li>
<li><a href="#">Inventory Inspection</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">Reprint</a></li>
<li><a href="#">Inventory Report</a></li>
</ul>
</li>
<li><a href="#">Reports</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
</ul>
</li>
</ul>
</div>
和css:
#cssmenu {padding: 0; margin: 0; border: 0;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding: 0;}
#cssmenu ul {position: relative; z-index: 597; }
#cssmenu ul li { float: left; min-height: 1px; vertical-align: middle; border:solid 1px blue; width:150px;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 599; cursor: default; background-color:yellow;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; width: 150px;}
#cssmenu ul ul li {float: none; margin-left:-1px; width:150px; border:solid 1px red;}
#cssmenu ul li:hover > ul { visibility: visible;}
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0; }
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; /*line-height: 1em;*/ text-decoration: none; }
这不漂亮,但你可以看到这一点。
It's not pretty but You can see the point.
更新(代码已更改):
#cssmenu
{
padding:0;
margin:0;
display:block;
}
a {text-decoration:none; color:black; width:100%; box-sizing:border-box; display:block;}
#cssmenu ul
{
position:relative;
margin:0;
padding:0;
cursor:default;
display:table;
width:100%;
border:solid 1px gray;
}
#cssmenu ul li, #cssmenu ul li:last-child
{
list-style-type:none;
display:table-cell;
text-align:center;
vertical-align:middle;
padding-top:3px;
padding-bottom:3px;
border-right:solid 1px gray;
margin:0;
position:relative;
}
#cssmenu ul li:last-child {border:none;}
#cssmenu ul li:hover {background-color:yellow;}
#cssmenu ul li:hover > a {color: red;}
#cssmenu ul ul
{
visibility:hidden;
position:absolute;
top:100%;
margin:0;
margin-left:-1px;
z-index:101;
display:block;
}
#cssmenu ul ul li, #cssmenu ul ul li:last-child
{
display:block;
width:100%;
box-sizing:border-box;
border:none;
border-bottom:solid 1px gray;
}
#cssmenu ul ul li:last-child {border:none;}
#cssmenu ul ul li:hover
{
background-color:navy;
}
#cssmenu ul li li:hover > a {color:white;}
#cssmenu ul li:hover > ul {visibility:visible;}
<div id='cssmenu'>
<ul>
<li><a href="#">Product Repository </a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">File Upload</a></li>
</ul>
</li>
<li><a href="#">Inventory Inspection</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">Reprint</a></li>
<li><a href="#">Inventory Report</a></li>
</ul>
</li>
<li><a href="#">Reports</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
</ul>
</li>
<li><a href="#">Product Repository </a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">File Upload</a></li>
</ul>
</li>
<li><a href="#">Inventory Inspection</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">Reprint</a></li>
<li><a href="#">Inventory Report</a></li>
</ul>
</li>
<li><a href="#">Reports</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
</ul>
</li>
<li><a href="#">Product Repository </a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">File Upload</a></li>
</ul>
</li>
<li><a href="#">Inventory Inspection</a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
<li><a href="#">Reprint</a></li>
<li><a href="#">Inventory Report</a></li>
</ul>
</li>
<li><a href="#">Product Repository </a>
<ul>
<li><a href="#">Insert</a></li>
<li><a href="#">Search & Edit</a></li>
</ul>
</li>
</ul>
</div>
,但是当您运行代码段
切换到完整页面
。我希望这是你想要的。但是,总是,如果你的窗口太小,你不能避免在两行中的项目值。
Try this solution, but when You Run code snippet
switch it to Full Page
. I hope so this is what You want. But, always but, if Your window is too small, You can't avoid item values in two rows.
这篇关于无法使菜单栏下拉正常悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!