[Bootstrap]组件(四)
导航条
移动设备上折叠(可开关),超过规定视口标签时候水平展开模式 依赖插件
注意点:导航条内元素过多或其他原因导致元素内元素宽度过长,会引起折行-->解决:a.减少导航内元素或者减少宽度 b.利用媒体查询或者响应工具类隐藏元素 c.修改媒体查询的值或者重置覆盖媒体查询的值
注意点:<nav>元素 || <div role="navigation"></div>
/* * 1 nav(.navbar.navbar-*:基类+状态类)(div元素需要额外添加role="navigation") * 2 div(.container-fluid:响应式容器) * 3 div(.navbar-header:导航条头部) + div(.collapse.navbar-collapse:折叠类+导航折叠类) * 3.1 导航条头部 内部:btn(.navbar-toggle.collapsed:导航开关类+被折叠类)+a(.navbar-brand:导航条商标类) * 3.2 折叠类+导航折叠类 内部:ul(.nav.navbar-nav:导航基类+导航条导航类)+(表单) */ <nav class="navbar navbar-default"> <!-- nav元素/div元素添加role="navigation" 基类.navbar 状态类.navbar-default --> <div class="container-fluid"> <!-- 容器.container-fluid 响应式容器 --> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <!-- 导航条头部 内容包括折叠按钮和logo/商标 --> <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" href="#">Brand</a> <!-- 导航条logo/商标 --> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <!-- 导航条的主要内容 可包含导航链接/表单/其他内容 在媒体查询的规定宽度下可折叠开关 --> <ul class="nav navbar-nav"> <!-- 导航 导航条下的导航 --> <li class="active"><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><a href="#">Another action</a></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> </ul> <form class="navbar-form navbar-left" role="search"> <!-- 导航条下的表单 --> <div class="form-group"> <!-- 表单组 --> <input type="text" class="form-control" placeholder="Search"> </div> <button type="submit" class="btn btn-default">Submit</button> </form> <ul class="nav navbar-nav navbar-right"> <!-- 导航 导航条下的导航 导航想右对齐 --> <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><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> </ul> </li> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav>
导航条中的品牌图标
.navbar-brand类中放置img元素,即可设置自己的商标,根据需要修改css或覆盖css
<nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href=""> <img src="..."/> </a> </div> </div> </nav>
导航条中的表单
<form class="navbar-form" role="search"> <div class="form-group"> <input type="text" class="form-control" placeholder="search" /> </div> <button type="submit" class="btn btn-default">submit</button> </form>
导航条中的按钮
<button type="button" class="btn btn-default navbar-btn">button</button>
导航条中的文本
<p class="navbar-text">navbar-text</p>
非导航的链接
<p class="navbar-text navbar-right">Signed in as <a href="#" class="navbar-link">Mark Otto</a></p>
组件排列
.navbar-left/.navbar-right -->导航链接/表单/按钮/文本对齐
最后一个.navbar-right设置了负边距,最好不要用多个.navbar-right
导航条固定在顶部
.navbar-fixed-top 固定的导航条引起遮挡body内部其他的信息,可能需要对其添加内补等额外样式
<nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> ... </div> </nav>
导航条静止在顶部
.navbar-static-top 不需要给body设置内补
<nav class="navbar navbar-default navbar-static-top"> <div class="container"> ... </div> </nav>
路径导航
面包屑.breadcrumb {padding/margin-bottom/list-style/background-color/border-radius}
<ol class="breadcrumb"> <li><a href="#">Home</a></li> <li><a href="#">Library</a></li> <li class="active">Data</li> </ol>
分页
nav>ul.pagination>li>a
<nav> <ul class="pagination"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <li><a href="#">1</a></li> <li><a href="#">2</a></li> <li><a href="#">3</a></li> <li><a href="#">4</a></li> <li><a href="#">5</a></li> <li> <a href="#" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav>
分页禁止和激活状态
禁止.disabled/激活.active
<nav> <ul class="pagination"> <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">«</span></a></li> <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li> ... </ul> </nav>
翻页
nav>ul.pager>li*2>a
<nav> <ul class="pager"> <li><a href="#">Previous</a></li> <li><a href="#">Next</a></li> </ul> </nav>
翻页两端对齐
nav>ul.pager>(li.previous>a)+(li.next>a)
<nav> <ul class="pager"> <li class="previous"><a href="#"><span aria-hidden="true">←</span> Older</a></li> <li class="next"><a href="#">Newer <span aria-hidden="true">→</span></a></li> </ul> </nav>