<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Test</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <link rel="stylesheet" href="./css/reset.css"> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <style> * { box-sizing: border-box; padding: 0; margin: 0; } div { line-height: 1; } .navbar { min-height: 50px; border: 2px solid transparent; } .navbar:after, .nav:after { content: ''; display: block; visibility: hidden; clear: both; } .navbar-default { background: #f9f9f9; border-color: #e7e7e7; } .navbar-header { line-height: .4; } .nav { list-style: none; } .nav > li > a, .navbar-header > a { display: block; padding: 10px 15px; } .caret { display: inline-block; margin: 5px; border-right: 4px solid transparent; border-left: 4px solid transparent; border-top: 4px dashed; } @media (min- 768px) { .navbar-header, .navbar-nav, .navbar-nav > li { float: left; } .navbar-nav > li > a, .navbar-header > a { padding: 15px; } } .dropdown { position: relative; } .dropdown-menu { display: none; position: absolute; top: 100%; left: 0; z-index: 100; border: 1px solid #ddd; border-radius: 4px; min- 100%; padding: 3px 0; } @keyframes fade { 0% { transform: translate3d(-100%,0,0); opacity: 0; } 100% { transform: translate3d(0,0,0); opacity: 1; } } .open > .dropdown-menu { display: block; } ul { list-style: none; } .dropdown-menu a { display: block; padding: 5px 20px; min- 100px; white-space: nowrap; } @media (max- 768px) { .dropdown-menu { position: static; border: none; } } @media (min- 768px) { .dropdown-menu .dropdown-menu { position: absolute; top: 0; left: 100%; } .dropdown-menu { animation: fade .3s ease-in alternate forwards; transition: all .2s; } } </style> </head> <body> <div class="navbar navbar-default" role="navigation"> <div class="navbar-header"> <a href="##" class="navbar-brand">慕课网</a> </div> <ul class="nav navbar-nav"> <li class="active"><a href="##">网站首页</a></li> <li class="dropdown"> <a href="##" data-toggle="dropdown" class="dropdown-toggle">系列教程<span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="##">CSS3</a></li> <li class="dropdown"> <a href="##" class="dropdown-toggle">JavaScript<span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="##">名师介绍</a></li> <li class="dropdown"> <a href="##" class="dropdown-toggle">成功案例<span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="##">CSS3</a></li> <li><a href="##">JavaScript</a></li> <li class="disabled"><a href="##">PHP</a></li> </ul> </li> <li><a href="##">关于我们</a></li> </ul> </li> <li class="disabled"><a href="##">PHP</a></li> </ul> </li> <li><a href="##">名师介绍</a></li> <li><a href="##">成功案例</a></li> <li><a href="##">关于我们</a></li> </ul> </div> <script> $('.dropdown-toggle').click(function(e) { e.stopPropagation(); $(this).parent().toggleClass('open'); }) $(document).click(function() { $('.dropdown').removeClass('open'); }) </script> </body> </html>