Heim > Artikel > Web-Frontend > 二级菜单不能顶头_html/css_WEB-ITnose
<!DOCTYPE html ><html><head> <title></title> <style > #menu,#submenu{ font-family:微软雅黑; font-size:medium;}/*菜单字体*/ #menu{width:100%} #menu ul,#submenu ul{ list-style:none;} /*去掉列表的点*/ #menu ul li,#submenu ul li{ float:left; padding:10px; width:120px; text-align:center}/*横向显示*/ #submenu{ text-align:left; display: block; position: inherit;} #menu ul li:hover{ border-bottom-style:solid; border-bottom-color:rgba(0,0,255,.5); cursor:pointer; color:rgba(255,0,0,.5);} #menu ul li:active{border-bottom-style:none; border-bottom-color:Red;cursor:pointer;color:Red;} .subfirst{ float:left; display:none;} </style> <script src="jquery.2.1.4.min.js" type="text/javascript"></script> <script type="text/javascript"> function showsub(rootid) { hidesub(); $('#submenu' + rootid).show(); } function hidesub() { for (var i = 1; i <= 3; i++) { $('#submenu' + i).hide(); } } </script></head><body> <div id="menu"> <ul> <li id="menu1" onmouseover="showsub(1)";">根菜单一</li> <li id="menu2" onmouseover="showsub(2)";">根菜单二</li> <li id="menu3" onmouseover="showsub(3)";">根菜单三</li> </ul> </div> <div id="submenu"> <ul id="submenu1" class="subfirst"> <li id="menu11">二级菜单1-1</li> <li id="menu12">二级菜单1-2</li> <li id="menu13">二级菜单1-3</li> </ul> <ul id="submenu2" class="subfirst"> <li id="menu21">二级菜单2-1</li> <li id="menu22">二级菜单2-2</li> <li id="menu23">二级菜单2-3</li> </ul> <ul id="submenu3" class="subfirst"> <li id="menu31">二级菜单3-1</li> <li id="menu32">二级菜单3-2</li> <li id="menu33">二级菜单3-3</li> </ul> </div></body></html>
#submenu{ text-align:left; display: block; position: inherit;clear: both;}
可以使用绝对布局position:absloute
然后设置left,top等