新增 bootstrap 导航条风格
大屏幕效果图:
小屏幕效果图:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> <title>导航菜单</title> <!-- Bootstrap --> <link href="bootstrap/css/bootstrap.css" rel="stylesheet" /> <link href="css/resetBootstrap.css" rel="stylesheet" /> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <div class="baseWidth"> <nav class="navbar navbar-reset navbar-red"> <div class="container-fluid container-fluid-reset"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand visible-xs-block" href="#"> <img src="images/logo.png" class="img-responsive" /> </a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse navbar-collapse-reset" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li><a href="#">Link <span class="sr-only">(current)</span></a></li> <li><a href="#">Link</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li role="separator" class="divider"></li> <li><a href="#">Another action</a></li> <li role="separator" class="divider"></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> <li role="separator" class="divider"></li> <li><a href="#">One more separated link</a></li> </ul> </li> <li><a href="#">Link <span class="sr-only">(current)</span></a></li> <li><a href="#">Link</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li role="separator" class="divider"></li> <li><a href="#">Another action</a></li> <li role="separator" class="divider"></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> <li role="separator" class="divider"></li> <li><a href="#">One more separated link</a></li> </ul> </li> <li><a href="#">Link <span class="sr-only">(current)</span></a></li> <li><a href="#">Link</a></li> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="bootstrap/js/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="bootstrap/js/bootstrap.js"></script> </body> </html>
改变菜单切换图标
关闭状态效果图:
打开状态效果图:
修改切换图标:
<div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <!--打开菜单图标--> <span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span> <!--关闭菜单图标--> <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> </button> <a class="navbar-brand visible-xs-block" href="#"> <img src="images/logo.png" class="img-responsive" /> </a> </div>
CSS代码:
.baseWidth { max-width:1200px; margin:0 20px; } @media (min-width: 768px) { .navbar-reset { position: relative; min-height: 50px; margin-bottom: 20px; border: 0; border-radius: 0px; } .container-fluid-reset { padding-left:0; padding-right:0; } .navbar-collapse-reset { padding-right: 0; padding-left: 0; overflow-x: visible; -webkit-overflow-scrolling: touch; border-top: 0px; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1); } } /*导航条样式*/ .navbar-red { background-color: #222; border-color: #ed1e23; } .navbar-red .navbar-header { background-color: #ed1e23; } .navbar-brand { float: left; height: 50px; width:50px; padding: 0 15px; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; } .navbar-red .navbar-brand { color: #9d9d9d; } .navbar-red .navbar-brand:hover, .navbar-red .navbar-brand:focus { color: #fff; background-color: transparent; } .navbar-red .navbar-text { color: #9d9d9d; } .navbar-red .navbar-nav > li > a { color: #FFF; } .navbar-red .navbar-nav > li > a:hover, .navbar-red .navbar-nav > li > a:focus { color: #fff; background-color:transparent; } .navbar-red .navbar-nav > .active > a, .navbar-red .navbar-nav > .active > a:hover, .navbar-red .navbar-nav > .active > a:focus { color: #fff; background-color: #080808; } .navbar-red .navbar-nav > .disabled > a, .navbar-red .navbar-nav > .disabled > a:hover, .navbar-red .navbar-nav > .disabled > a:focus { color: #444; background-color: transparent; } .navbar-red .navbar-toggle { position: relative; float: right; padding: 17px 10px; margin-top:0; margin-right: 0; margin-bottom: 0; background-color: #000; background-image: none; border: 1px solid #000; border-radius: 0; } .navbar-red .navbar-toggle:hover, .navbar-red .navbar-toggle:focus { background-color: #000; } .navbar-red .navbar-toggle .icon-bar { background-color: #fff; } /*改变导航切换图标*/ .navbar-red .navbar-toggle .glyphicon { color: #fff; font-size:24px; } .navbar-red .navbar-toggle >.glyphicon-menu-hamburger { display:none; } .navbar-red .navbar-toggle >.glyphicon-remove { display:block; } /* 通过 collapsed 切换图标显示状态*/ .navbar-red .navbar-toggle.collapsed >.glyphicon-menu-hamburger { display:block; } .navbar-red .navbar-toggle.collapsed >.glyphicon-remove { display:none; } .navbar-red .navbar-collapse, .navbar-red .navbar-form { border-color: #000; -webkit-box-shadow: inset 0 0 0 rgba(255, 255, 255, .1); box-shadow: inset 0 0 0 rgba(255, 255, 255, .1); } .navbar-red .navbar-nav > .open > a, .navbar-red .navbar-nav > .open > a:hover, .navbar-red .navbar-nav > .open > a:focus { color: #fff; background-color: #080808; } @media (max-width: 767px) { .navbar-red .navbar-nav .open .dropdown-menu > .dropdown-header { border-color: #080808; } .navbar-red .navbar-nav .open .dropdown-menu .divider { background-color: #080808; } .navbar-red .navbar-nav .open .dropdown-menu > li > a { color: #9d9d9d; } .navbar-red .navbar-nav .open .dropdown-menu > li > a:hover, .navbar-red .navbar-nav .open .dropdown-menu > li > a:focus { color: #fff; background-color: transparent; } .navbar-red .navbar-nav .open .dropdown-menu > .active > a, .navbar-red .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar-red .navbar-nav .open .dropdown-menu > .active > a:focus { color: #fff; background-color: #080808; } .navbar-red .navbar-nav .open .dropdown-menu > .disabled > a, .navbar-red .navbar-nav .open .dropdown-menu > .disabled > a:hover, .navbar-red .navbar-nav .open .dropdown-menu > .disabled > a:focus { color: #444; background-color: transparent; } } @media (min-width: 768px) { .navbar-red { background-color: #222; border-color: #080808; } .navbar-red .navbar-nav { width:100%; margin: 0; } .navbar-red .navbar-nav > li { width:12.5%; height:50px; } .navbar-red .navbar-nav > li > a { height:50px; text-align:center; } .navbar-red .navbar-nav > li > a:hover, .navbar-red .navbar-nav > li > a:focus { color: #fff; background-color: #080808; } } .navbar-red .navbar-link { color: #9d9d9d; } .navbar-red .navbar-link:hover { color: #fff; } .navbar-red .btn-link { color: #9d9d9d; } .navbar-red .btn-link:hover, .navbar-red .btn-link:focus { color: #fff; } .navbar-red .btn-link[disabled]:hover, fieldset[disabled] .navbar-red .btn-link:hover, .navbar-red .btn-link[disabled]:focus, fieldset[disabled] .navbar-red .btn-link:focus { color: #444; }