BootStrap 导航条实例代码


Posted in Javascript onMay 18, 2017

一、默认的导航条

制作默认的导航条,可分以下几步:

1.在ul里加上(ul class="nav navbar-nav")样式;

2.在ul外加一层div或nav(ps:HTML5新属性),并且添加样式(div class="navbar nabar-default");

<nav class="navbar navbar-default">
  <ul class="nav navbar-nav">
   <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >吃饭</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >睡觉</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >打勇士</a></li>
  </ul>
</nav>

如图下:

BootStrap 导航条实例代码

So easy吧qaq

二、带有表单的导航条

1.在默认导航条的基础上,再一个form。

2.form中应用样式(form class="navbar-form")

<nav class="navbar navbar-default">
  <ul class="nav navbar-nav">
   <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >吃饭</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >睡觉</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >打勇士</a></li>
  </ul>
  <form class="navbar-form">
   <input type="text" class="form-control" placeholder="猜猜是谁?">
   
   <input type="submit" class="form-control" value="我瞧瞧~">
  </form>
</nav>

如图下:

BootStrap 导航条实例代码

擦,写错了,其实我想写打火箭的。。。

三、表单,下拉菜单等冗合的导航条

上一个综合例子,不然一个一个写,小编得coding到天亮,废话少说,直说上料。

<nav class="navbar navbar-default">
  <ul class="nav navbar-nav">
   <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >吃饭</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >睡觉</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >打勇士</a></li>
   <li class="dropdown">
    <a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-toggle="dropdown" class="dropdown-toggle">西决几比几<span class="caret"></span></a>
    <ul class="dropdown-menu">
    <li><a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4:0</a></li>
    <li><a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4:1</a></li>
    <li class="disabled"><a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4:2</a></li>
    </ul>
   </li>
  </ul>
  <form class="navbar-form">
   <input type="text" class="form-control" placeholder="猜猜是谁?">
   
   <input type="submit" class="form-control" value="我瞧瞧~">
  </form>
</nav>

如图下:

BootStrap 导航条实例代码

咳咳,一般导航都有个大标题,如图下:

BootStrap 导航条实例代码

实现步骤:

1.在div里添加样式(div class="navbar-header");

2.在此div添加a标签(a class="navbar-brand");

navbar-brand(品牌)也就是大标题啦!

<nav class="navbar navbar-default">
  <div class="navbar-header">
   <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="navbar-brand">阿尔德里奇</a>
  </div>
  <ul class="nav navbar-nav">
   <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >吃饭</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >睡觉</a></li>
   <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >打勇士</a></li>
   <li class="dropdown">
    <a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-toggle="dropdown" class="dropdown-toggle">西决几比几<span class="caret"></span></a>
    <ul class="dropdown-menu">
    <li><a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4:0</a></li>
    <li><a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4:1</a></li>
    <li class="disabled"><a href="##" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4:2</a></li>
    </ul>
   </li>
  </ul>
  <form class="navbar-form">
   <input type="text" class="form-control" placeholder="猜猜是谁?">
   
   <input type="submit" class="form-control" value="我瞧瞧~">
  </form>
</nav>

四、反色导航条

反色导航条其实是Bootstrap框架为大家提供的第二种风格的导航条,只是将"navbar-deafult"类名换成"navbar-inverse"。其他不变,见下图:

BootStrap 导航条实例代码

个人还是比较喜欢这个风格的,够装逼~

五、固定导航条

顾名思义,其实就是fixed样式,

Bootstrap框架提供了两种固定导航条的方式:

.navbar-fixed-top:导航条固定在浏览器窗口顶部

.navbar-fixed-bottom:导航条固定在浏览器窗口底部

使用方法很简单,只需要在制作导航条最外部容器navbar上追加对应的类名即可

<!--导航条固定在浏览器窗口顶部-->
<div class="navbar navbar-default navbar-fixed-top">
  …
</div>
<!--导航条固定在浏览器窗口底部-->
<div class="navbar navbar-default navbar-fixed-bottom">
  …
</div>

六、响应式导航条

<div class="navbar navbar-inverse navbar-fixed-top">
 <div class="container">
  <div class="navbar-header">
    <!-- .navbar-toggle样式用于toggle收缩的内容,即navbar-collapse collapse样式所在元素,-->
   <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
    <span class="sr-only">Toggle Navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
   </button>
   <!-- 确保无论是宽屏还是窄屏,navbar-brand都显示 -->
   <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="navbar-brand">我的主页</a>
  </div>
  <!-- 屏幕宽度小于768px时,div.navbar-collapse容器里的内容都会隐藏,显示icon-bar图标,当点击icon-bar图标时,再展开。屏幕大于768px时,默认显示。 -->
  <div id="navbar" class=" collapse navbar-collapse">
   <ul class="nav navbar-nav">
    <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >吃饭</a></li>
    <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >睡觉</a></li>
    <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >打火箭</a></li>
   </ul>
  </div>
 </div>
</div>

我这是套的反色导航条的,现在分别看下宽屏和窄屏的显示效果,如图下:

BootStrap 导航条实例代码

BootStrap 导航条实例代码

<button>里面是窄屏右上角的按钮,span标签是三道杠,

现在说一下上面代码中第5行,data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar",这都什么跟什么啊,我这逐一介绍一下;

data-toggle="collapse"     代表     告诉js要什么事件来触发,此处的coolapse为“伸展折叠”;

data-target="#navbar"     代表     谁要以伸展折叠的方式来展示,绑定的是ID;

aria-expanded="false"      代表   是否展开,false。

谈到这aria-*,为无障碍网页应用。主要针对的是视觉缺陷,失聪,行动不便的残疾人以及假装残疾的测试人员。尤其像盲人,眼睛看不到,其浏览网页则需要借助辅助设备,如屏幕阅读器,屏幕阅读机可以大声朗读或者输出盲文。

以上所述是小编给大家介绍的BootStrap 导航条实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
javascript入门·动态的时钟,显示完整的一些方法,新年倒计时
Oct 01 Javascript
js获取或设置当前窗口url参数的小例子
Oct 14 Javascript
基于HTML+CSS+JS实现增加删除修改tab导航特效代码
Aug 05 Javascript
Vue.JS入门教程之自定义指令
Dec 08 Javascript
vue子组件使用自定义事件向父组件传递数据
May 27 Javascript
jquery点击回车键实现登录效果并默认焦点的方法
Mar 09 jQuery
关于vuejs中v-if和v-show的区别及v-show不起作用问题
Mar 26 Javascript
记一次vue-webpack项目优化实践详解
Feb 17 Javascript
JavaScript刷新页面的几种方法总结
Mar 28 Javascript
Layui带搜索的下拉框的使用以及动态数据绑定方法
Sep 28 Javascript
JS图片懒加载技术实现过程解析
Jul 27 Javascript
微信小程序自定义yPicker组件实现省市区三级联动功能
Oct 29 Javascript
AngularJS全局警告框实现方法示例
May 18 #Javascript
第一次记录Bootstrap table学习笔记(1)
May 18 #Javascript
原生js轮播特效
May 18 #Javascript
js实现放大镜特效
May 18 #Javascript
vue v-on监听事件详解
May 17 #Javascript
vue v-model表单控件绑定详解
May 17 #Javascript
Bootstrap 表单验证formValidation 实现表单动态验证功能
May 17 #Javascript
You might like
php strcmp使用说明
2010/04/22 PHP
PHP中常用的转义函数
2014/02/28 PHP
php使用ob_flush不能每隔一秒输出原理分析
2015/06/02 PHP
大家须知简单的php性能优化注意点
2016/01/04 PHP
Laravel 实现添加多语言提示信息
2019/10/25 PHP
JavaScript 读取元素的CSS信息的代码
2010/02/07 Javascript
Javascript在IE和FireFox中的不同表现简析
2012/12/03 Javascript
JS刷新框架外页面七种实现代码
2013/02/18 Javascript
JS去除数组重复值的五种不同方法
2013/09/06 Javascript
JavaScript中String.prototype用法实例
2015/05/20 Javascript
jQuery实现点击按钮弹出可关闭层的浮动层插件
2015/09/19 Javascript
JS弹出对话框实现方法(三种方式)
2015/12/18 Javascript
解析javascript瀑布流原理实现图片滚动加载
2016/03/10 Javascript
BootStrap中Tab页签切换实例代码
2016/05/30 Javascript
JS作用域深度解析
2016/12/29 Javascript
js 获取今天以及过去日期
2017/04/11 Javascript
荐书|您有一份JavaScript书单待签收
2017/07/21 Javascript
Vue结合后台导入导出Excel问题详解
2019/02/19 Javascript
小程序实现投票进度条
2019/11/20 Javascript
Angular如何由模板生成DOM树的方法
2019/12/23 Javascript
[01:38]2018DOTA2亚洲邀请赛主赛事第二日现场采访 神秘商人痛陈生计不易
2018/04/05 DOTA
用Python制作检测Linux运行信息的工具的教程
2015/04/01 Python
编写Python脚本来实现最简单的FTP下载的教程
2015/05/04 Python
win7下python3.6安装配置方法图文教程
2018/07/31 Python
Pandas之MultiIndex对象的示例详解
2019/06/25 Python
Python Matplotlib 基于networkx画关系网络图
2019/07/10 Python
Python reduce函数作用及实例解析
2020/05/08 Python
Python 解析简单的XML数据
2020/07/24 Python
python爬虫利用代理池更换IP的方法步骤
2021/02/21 Python
德国2018年度最佳在线药房:Bodfeld Apotheke
2019/11/04 全球购物
奖学金自我鉴定范文
2013/10/03 职场文书
银行财务部实习生的自我鉴定
2013/11/27 职场文书
初中同学聚会感言
2014/02/11 职场文书
企业宣传标语
2014/06/09 职场文书
教师求职信怎么写
2015/03/20 职场文书
演讲开头怎么书写?
2019/08/06 职场文书