亲宝软件园·资讯

展开

Bootstrap基本组件学习笔记之导航(10)

kikay 人气:0

Bootstrap的导航很有特色,主要分为胶囊式导航、面包屑导航、头部导航共3大类,可以满足绝大部分需求。

0x01 胶囊式导航

胶囊式导航采用的是无序列表ul来实现:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link href="../../css/bootstrap.min.css" rel="stylesheet">
 <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <script src="../../js/bootstrap.min.js"></script>
 <title>胶囊式导航</title>
</head>
<body>
<div class="container">
 <div class="page-header">
 <h1>胶囊式导航</h1>
 </div>
 <div class="col-lg-3">
 <h3>水平样式</h3>
 <ul class="nav nav-pills">
  <li class="active"><a href="#">首页</a></li>
  <li><a href="#">新闻</a></li>
  <li><a href="#">关于</a></li>
 </ul>
 </div>
 <div class="col-lg-3">
 <h3>垂直样式</h3>
 <ul class="nav nav-pills nav-stacked">
  <li class="active"><a href="#">首页</a></li>
  <li><a href="#">新闻</a></li>
  <li><a href="#">关于</a></li>
 </ul>
 </div>
</div>
</body>
</html>

效果如下:

0x02面包屑导航

面包屑导航采用的是有序列表ol来实现:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link href="../../css/bootstrap.min.css" rel="stylesheet">
 <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <script src="../../js/bootstrap.min.js"></script>
 <title>面包屑导航</title>
</head>
<body>
<div class="container">
 <div class="page-header">
 <h1>面包屑导航</h1>
 </div>
 <div class="breadcrumb">
 <li class="active"><a href="#">学校</a></li>
 <li><a href="#">一年级</a></li>
 <li><a href="#">一班</a></li>
 </div>
</div>
</body>
</html>

效果如下:

0x03 头部导航

头部导航在网站开发中比较常见,依赖于Bootstrap库的collapse插件。基本样式如下:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link href="../../css/bootstrap.min.css" rel="stylesheet">
 <style>
 /*body{*/
  /*padding-top: 50px;*/
 /*}*/
 </style>
 <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <script src="../../js/bootstrap.min.js"></script>
 <title>头部导航</title>
</head>
<body>
<div class="container">
 <nav class="navbar navbar-inverse">
 <div class="navbar-header">
  <button type="button" class="btn btn-default navbar-toggle" data-toggle="collapse" data-target="#navbar">
  <span class="sr-only">Toggle navigation</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="navbar">
  <ul class="nav navbar-nav">
  <li class="active"><a href="#">首 页</a></li>
  <li><a href="#">新闻</a></li>
  <li class="dropdown">
   <a href="#" class="dropdown-toggle" data-toggle="dropdown">
   下拉菜单
   <span class="caret"></span>
   </a>
   <ul class="dropdown-menu">
   <li><a href="#">菜单1</a></li>
   <li><a href="#">菜单2</a></li>
   <li><a href="#">菜单3</a></li>
   </ul>
  </li>
  </ul>
  <form class="nav navbar-form navbar-right">
  <div class="form-group">
   <input type="text" class="form-control" placeholder="用户名">
  </div>
  <div class="form-group">
   <input type="password" class="form-control" placeholder="密码">
  </div>
  <div class="form-group">
   <button type="submit" class="btn btn-primary form-control">提 交</button>
  </div>
  </form>
 </div>
 </nav>
 <div class="page-header">
 <h1>头部导航</h1>
 </div>
 <div>
 <p>内容</p>
 </div>
</div>
</body>
</html>

效果如下:

当屏幕宽度很窄时,会出现下面样式:

这是因为我们在实现过程中使用了如下代码:

<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>


如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap插件使用教程

加载全部内容

相关教程
猜你喜欢
用户评论