大家好,又见面了,我是你们的朋友全栈君。
1. 定义导航条
<!-- 导航条 navbar -->
<div class="navbar nav-bar-default">
<ul class="nav nav-pills">
<li class="active"><a href="#">首页</a></li>
<li><a href="#">登录</a></li>
<li><a href="#">退出</a></li>
</ul>
</div>
添加网站表示名(navbar-brand)
<div class="navbar nav-bar-default">
<a href="#" class="navbar-brand">伊人考试系统</a>
<ul class="nav nav-pills">
<li class="active"><a href="#">首页</a></li>
<li><a href="#">登录</a></li>
<li><a href="#">退出</a></li>
</ul>
</div>
导航条包括链接、下拉菜单、网站标题和折叠按钮
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#menu">
<span class="sr-only">展开导航</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand">网站标题</a>
</div>
<div class="collapse navbar-collapse" id="menu">
<ul class="nav navbar-nav">
<li><a href="#">首页</a></li>
<li><a href="#">导航标题1</a></li>
<li><a href="#">导航标题2</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
下拉菜单<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="#">下拉菜单1</a></li>
<li class="divider"></li>
<li><a href="#">下拉菜单2</a></li>
<li class="divider"></li>
</ul>
</li>
</ul>
</div>
</nav>
2. 绑定对象
- 包裹菜单
<!-- 导航条 包裹表单 -->
<nav class="navbar navbar-default" role="navigation">
<a href="#" class="navbar-brand">网站标题</a>
<form action="" class="navbar-form navbar-left" role="search">
<div class="form-group"><input type="text" class="form-control" placeholder="关键字"></div>
<button class="btn btn-default" type="submit">提交</button>
</form>
</nav>
- 包裹下拉菜单
<!-- 导航条 包裹下拉菜单 -->
<div class="navbar navbar-default">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" data-toggle="dropdown">分享 <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">QQ</a></li>
<li><a href="#">微信</a></li>
<li><a href="#">微博</a></li>
</ul>
</li>
</ul>
</div>
- 包裹按钮(navbar-btn类)
<div class="navbar navbar-default">
<button class="btn btn-default navbar-btn" type="button">按钮1</button>
<button class="btn btn-primary navbar-btn" type="button">按钮2</button>
<button class="btn btn-default navbar-btn" type="button">按钮3</button>
</div>
- 包裹文本(navbar-text)和链接(navbar-link)
<div class="navbar navbar-default">
<button class="btn btn-default navbar-btn" type="button">按钮</button>
<p class="navbar-text">欢迎登录!</p>
<p class="navbar-text">
普通段落<a href="#" class="navbar-link">链接</a></p>
</div>
3. 设计导航条
- 置顶导航条(.navbar-fixed-top .navbar-static-top)
navbar-fixed-top和navbar-static-top的区别:
fixed会吸附在顶部,static在页面下拉滚动式会消失
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 导航条</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shiv 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<style>
body{
padding-top: 50px;
}
</style>
</head>
<body>
<!-- 导航条 包裹文本 -->
<div class="navbar navbar-default navbar-fixed-top">
<a href="#" class="navbar-brand">置顶导航条</a>
<form action="#" class="navbar-form navbar-left" role="search">
<div class="form-group"><input type="text" class="form-control" placeholder="关键字"></div>
<button class="btn btn-default" type="submit">搜索</button>
</form>
</div>
<div style="height:2000px;border: solid 1px red;margin:6px;"><img src="https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1556259084&di=29d728888a58d093701439b1abbf8d3b&src=http://img.pconline.com.cn/images/upload/upc/tx/itbbs/1410/19/c6/39851563_1413703610908.jpg" alt="" class="img-responsive"></div>
<!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) -->
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<!-- 包括所有已编译的插件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
- 置底导航条(navbar-fixed-bottom)
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 导航条</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shiv 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- 导航条 包裹文本 -->
<div class="navbar navbar-default navbar-fixed-bottom" role="navigation">
<a href="#" class="navbar-brand">置顶导航条</a>
<form action="#" class="navbar-form navbar-left" role="search">
<div class="form-group"><input type="text" class="form-control" placeholder="关键字"></div>
<button class="btn btn-default" type="submit">搜索</button>
</form>
</div>
<div style="height:2000px;border: solid 1px red;margin:6px;">
<img src="http://img.pconline.com.cn/images/upload/upc/tx/itbbs/1410/19/c6/39851563_1413703610908.jpg" alt="" class="img-responsive">
</div>
<!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) -->
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<!-- 包括所有已编译的插件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
- 设计导航条反色效果
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 导航条</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shiv 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<style>
body{
padding-top: 50px;
}
</style>
</head>
<body>
<!-- 导航条 包裹文本 -->
<div class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
<a href="#" class="navbar-brand">置顶导航条</a>
<form action="#" class="navbar-form navbar-left" role="search">
<div class="form-group"><input type="text" class="form-control" placeholder="关键字"></div>
<button class="btn btn-default" type="submit">搜索</button>
</form>
</div>
<div style="height:2000px;border: solid 1px red;margin:6px;"><img src="https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1556259084&di=29d728888a58d093701439b1abbf8d3b&src=http://img.pconline.com.cn/images/upload/upc/tx/itbbs/1410/19/c6/39851563_1413703610908.jpg" alt="" class="img-responsive"></div>
<!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) -->
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<!-- 包括所有已编译的插件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
- 设计响应式导航条
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 导航条</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shiv 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- 导航条 包裹文本 -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#a">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav navbar-nav collapse navbar-collapse" id="a">
<li class="active"><a href="#">首页</a></li>
<li><a href="#">微博</a></li>
<li><a href="#">微信</a></li>
</ul>
</div>
<div style="height:2000px;border: solid 1px red;margin:6px;"><img src="https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1556259084&di=29d728888a58d093701439b1abbf8d3b&src=http://img.pconline.com.cn/images/upload/upc/tx/itbbs/1410/19/c6/39851563_1413703610908.jpg" alt="" class="img-responsive"></div>
<!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) -->
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<!-- 包括所有已编译的插件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/129314.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...