bootstrap 实现自适应导航栏
程序员文章站
2023-12-30 18:01:46
...
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>Bootstrap--模板</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="css/bootstrap.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!--导航条包含容器,而不是容器包含导航条-->
<div class="navbar navbar-default">
<div class="container">
<!--第一部分:导航栏头部 = 品牌 + 汉堡包-->
<div class="navbar-header">
<!--品牌-->
<a href="#" class="navbar-brand">Tarena</a>
<!--汉堡包-->
<a href="#startNav" data-toggle="collapse"
class="navbar-toggle">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
</div>
<!--第二部分:导航+按钮+超链接+文本-->
<div id="startNav" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="#">首页</a></li>
<li><a href="#">新闻</a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown">产品大全</a>
<ul class="dropdown-menu">
<li>MP3</li>
<li>MP4</li>
<li>DVD</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<!--底部导航栏:-->
<div class="navbar
navbar-inverse navbar-fixed-bottom">
<div class="container">
<!--第一部分:导航条头部=品牌+汉堡包-->
<div class="navbar-header">
<a href="#" class="navbar-brand">Tarena</a>
<a href="#my-menu2" data-toggle="collapse"
class="navbar-toggle">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
</div>
<!--第二部分:导航条折叠=导航+按钮+超链接+文本-->
<div id="my-menu2" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="#">首页</a></li>
<li><a href="#">相册</a></li>
<li><a href="#">新闻</a></li>
</ul>
</div>
</div>
</div>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
.navbar-toggle 媒体查询:屏幕宽度大于768px 就隐藏
.navbar-collapse 媒体查询:屏幕宽度大于768px 绝对定位在
.navbar-header内;否则相对定位.navbar-header