下拉菜单列表问题
我试图使下拉菜单列表内联(水平)显示,但最终垂直显示。如果我将 ul_dropdown 宽度设置为 600px 左右,它将达到我想要的结果。但是,我希望它在不设置宽度的情况下完成此操作。这是我简化的 html/css:
<style type="text/css">
#menu {
list-style:none;
}
#menu .item{
display:inline;
position:relative;
float:left;
width:100px;
height:20px;
text-align:center;
}
#menu .item .ul_dropdown{
position:absolute;
float:left;
left:-999em;
list-style:none;
margin:0px;
padding:0px;
border:2px solid red;
}
#menu .item .ul_dropdown li h3{
margin:0px;
padding:0px;
}
#menu .item .ul_dropdown li{
display:inline;
position:relative;
float:left;
list-style:none;
margin-right:1px;
}
#menu .item .ul_dropdown li ul{
display:inline!important;
position:relative;
float:left;
padding:0px;
margin:0px;
width:200px;
}
#menu .item .ul_dropdown li ul li{
border:1px solid blue;
width:200px;
height:22px;
}
#menu .item:hover{
background-color:red;
}
#menu .item:hover .ul_dropdown {
left:0px;
top:auto;
}
#menu .item:hover .ul_dropdown li
{
display:inline;
width:200px;
}
</style>
<ul id="menu">
<li class="item">Main
<ul class="ul_dropdown">
<li><h3>Sales</h3>
<ul>
<li>Sales Sample 1</li>
<li>Sales Sample 2</li>
<li>Sales Sample 3</li>
</ul>
</li>
<li><h3>Invoice</h3>
<ul>
<li>Invoice Sample 1</li>
<li>Invoice Sample 2</li>
</ul>
</li>
<li><h3>Deal</h3>
<ul>
<li>Deal Sample 1</li>
<li>Deal Sample 2</li>
<li>Deal Sample 3</li>
</ul>
</li>
</ul>
<li class="item">1st Menu
</li>
<li class="item">2nd Menu
</li>
<li class="item">3rd Menu
</li>
</ul>
I am trying to make the drop down menu lists display inline(horizontally) but end up vertically. If I set the ul_dropdown width to 600px or so, it'll do the result I want. However, I want it to do it without me setting the width. Here's my simplified html/css:
<style type="text/css">
#menu {
list-style:none;
}
#menu .item{
display:inline;
position:relative;
float:left;
width:100px;
height:20px;
text-align:center;
}
#menu .item .ul_dropdown{
position:absolute;
float:left;
left:-999em;
list-style:none;
margin:0px;
padding:0px;
border:2px solid red;
}
#menu .item .ul_dropdown li h3{
margin:0px;
padding:0px;
}
#menu .item .ul_dropdown li{
display:inline;
position:relative;
float:left;
list-style:none;
margin-right:1px;
}
#menu .item .ul_dropdown li ul{
display:inline!important;
position:relative;
float:left;
padding:0px;
margin:0px;
width:200px;
}
#menu .item .ul_dropdown li ul li{
border:1px solid blue;
width:200px;
height:22px;
}
#menu .item:hover{
background-color:red;
}
#menu .item:hover .ul_dropdown {
left:0px;
top:auto;
}
#menu .item:hover .ul_dropdown li
{
display:inline;
width:200px;
}
</style>
<ul id="menu">
<li class="item">Main
<ul class="ul_dropdown">
<li><h3>Sales</h3>
<ul>
<li>Sales Sample 1</li>
<li>Sales Sample 2</li>
<li>Sales Sample 3</li>
</ul>
</li>
<li><h3>Invoice</h3>
<ul>
<li>Invoice Sample 1</li>
<li>Invoice Sample 2</li>
</ul>
</li>
<li><h3>Deal</h3>
<ul>
<li>Deal Sample 1</li>
<li>Deal Sample 2</li>
<li>Deal Sample 3</li>
</ul>
</li>
</ul>
<li class="item">1st Menu
</li>
<li class="item">2nd Menu
</li>
<li class="item">3rd Menu
</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
display:inline-block;
和/或float:left;
作为您的 li。 必须工作!Use
display:inline-block;
and/orfloat:left;
for your li's. Has to work!尝试查看一些告诉您如何执行此操作的教程。
http://www.cssnewbie.com/horizontal-dropdown-menus/
Try looking over a few tutorials that tell you how to do this.
http://www.cssnewbie.com/horizontal-dropdown-menus/