Bootstrap的导航条下拉菜单为了适应移动设备没有鼠标hover的状态,都是点击弹出下拉菜单,为了适应一般网站使用,我稍作了一些修改,鼠标hover时就弹出二级菜单。
效果图:
CSS修改:
<style type="text/css">
.navbar .nav > li .dropdown-menu {
margin: 0;
}
.navbar .nav > li:hover .dropdown-menu {
display: block;
}
</style>
实例源码:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Bootstrap导航条鼠标悬停下拉菜单</title> <link type="text/css" href="https://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css"> <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript" src="https://apps.bdimg.com/libs/bootstrap/3.3.4/js/bootstrap.min.js"></script> <style type="text/css"> .navbar .nav > li .dropdown-menu { margin: 0; } .navbar .nav > li:hover .dropdown-menu { display: block; } </style> </head> <body> <div> <div> <div> <ul> <li><a href="#">Home</a></li> <li><a href="#">SVN<span></span></a> <ul> <li><a href="#">sub SVN1</a></li> <li><a href="#">sub SVN2</a></li> </ul> </li> <li><a href="#">iOS</a></li> <li><a href="#">VB.Net</a></li> <li><a href="#">Java<span></span></a> <ul> <li><a href="#">sub Java1</a></li> <li><a href="#">sub Java2</a></li> </ul> </li> <li><a href="#">PHP</a></li> </ul> </div> </div> </div> </body> </html>