和 元素上。
不要在
.navbar-nav 内的 元素上使用
.navbar-btn,因为它不是标准的 button class。
下面的实例演示了这点:
实例
<
nav
class
=
"
navbar navbar-default
"
role
=
"
navigation
"
>
<
div
class
=
"
container-fluid
"
>
<
div
class
=
"
navbar-header
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
菜鸟教程
a
>
div
>
<
div
>
<
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
"
>
提交按钮
button
>
form
>
<
button
type
=
"
button
"
class
=
"
btn btn-default navbar-btn
"
>
导航栏按钮
button
>
div
>
div
>
nav
>
尝试一下 »
结果如下所示:
导航栏中的文本
如果需要在导航中包含文本字符串,请使用 class .navbar-text。这通常与
标签一起使用,确保适当的前导和颜色。下面的实例演示了这点:
实例
<
nav
class
=
"
navbar navbar-default
"
role
=
"
navigation
"
>
<
div
class
=
"
container-fluid
"
>
<
div
class
=
"
navbar-header
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
菜鸟教程
a
>
div
>
<
div
>
<
p
class
=
"
navbar-text
"
>
Runoob 用户登录
p
>
div
>
div
>
nav
>
尝试一下 »
结果如下所示:
结合图标的导航链接
如果您想在常规的导航栏导航组件内使用图标,那么请使用 class glyphicon glyphicon-* 来设置图标,更多请查看 Bootstrap 图标 ,如下面的实例所示:
实例
<
nav
class
=
"
navbar navbar-default
"
role
=
"
navigation
"
>
<
div
class
=
"
container-fluid
"
>
<
div
class
=
"
navbar-header
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
菜鸟教程
a
>
div
>
<
ul
class
=
"
nav navbar-nav navbar-right
"
>
<
li
>
<
a
href
=
"
#
"
>
<
span
class
=
"
glyphicon glyphicon-user
"
>
span
>
注册
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
<
span
class
=
"
glyphicon glyphicon-log-in
"
>
span
>
登录
a
>
li
>
ul
>
div
>
nav
>
尝试一下 »
结果如下所示:
组件对齐方式
您可以使用实用工具 class .navbar-left 或 .navbar-right 向左或向右对齐导航栏中的 导航链接、表单、按钮或文本 这些组件。这两个 class 都会在指定的方向上添加 CSS 浮动。下面的实例演示了这点:
实例
<
nav
class
=
"
navbar navbar-default
"
role
=
"
navigation
"
>
<
div
class
=
"
container-fluid
"
>
<
div
class
=
"
navbar-header
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
菜鸟教程
a
>
div
>
<
div
>
<
ul
class
=
"
nav navbar-nav navbar-left
"
>
<
li
class
=
"
dropdown
"
>
<
a
href
=
"
#
"
class
=
"
dropdown-toggle
"
data-toggle
=
"
dropdown
"
>
Java
<
b
class
=
"
caret
"
>
b
>
a
>
<
ul
class
=
"
dropdown-menu
"
>
<
li
>
<
a
href
=
"
#
"
>
jmeter
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
EJB
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
Jasper Report
a
>
li
>
<
li
class
=
"
divider
"
>
li
>
<
li
>
<
a
href
=
"
#
"
>
分离的链接
a
>
li
>
<
li
class
=
"
divider
"
>
li
>
<
li
>
<
a
href
=
"
#
"
>
另一个分离的链接
a
>
li
>
ul
>
li
>
ul
>
<
form
class
=
"
navbar-form navbar-left
"
role
=
"
search
"
>
<
button
type
=
"
submit
"
class
=
"
btn btn-default
"
>
向左对齐-提交按钮
button
>
form
>
<
p
class
=
"
navbar-text navbar-left
"
>
向左对齐-文本
p
>
<
ul
class
=
"
nav navbar-nav navbar-right
"
>
<
li
class
=
"
dropdown
"
>
<
a
href
=
"
#
"
class
=
"
dropdown-toggle
"
data-toggle
=
"
dropdown
"
>
Java
<
b
class
=
"
caret
"
>
b
>
a
>
<
ul
class
=
"
dropdown-menu
"
>
<
li
>
<
a
href
=
"
#
"
>
jmeter
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
EJB
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
Jasper Report
a
>
li
>
<
li
class
=
"
divider
"
>
li
>
<
li
>
<
a
href
=
"
#
"
>
分离的链接
a
>
li
>
<
li
class
=
"
divider
"
>
li
>
<
li
>
<
a
href
=
"
#
"
>
另一个分离的链接
a
>
li
>
ul
>
li
>
ul
>
<
form
class
=
"
navbar-form navbar-right
"
role
=
"
search
"
>
<
button
type
=
"
submit
"
class
=
"
btn btn-default
"
>
向右对齐-提交按钮
button
>
form
>
<
p
class
=
"
navbar-text navbar-right
"
>
向右对齐-文本
p
>
div
>
div
>
nav
>
尝试一下 »
结果如下所示:
固定到顶部
Bootstrap 导航栏可以动态定位。默认情况下,它是块级元素,它是基于在 HTML 中放置的位置定位的。通过一些帮助器类,您可以把它放置在页面的顶部或者底部,或者您可以让它成为随着页面一起滚动的静态导航栏。
如果您想要让导航栏固定在页面的顶部,请向 .navbar class 添加 class .navbar-fixed-top。下面的实例演示了这点:
为了防止导航栏与页面主体中的其他内容的顶部相交错,请向
标签添加至少 50 像素的内边距(padding),内边距的值可以根据您的需要进行设置。
实例
<
nav
class
=
"
navbar navbar-default navbar-fixed-top
"
role
=
"
navigation
"
>
<
div
class
=
"
container-fluid
"
>
<
div
class
=
"
navbar-header
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
菜鸟教程
a
>
div
>
<
div
>
<
ul
class
=
"
nav navbar-nav
"
>
<
li
class
=
"
active
"
>
<
a
href
=
"
#
"
>
iOS
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
SVN
a
>
li
>
<
li
class
=
"
dropdown
"
>
<
a
href
=
"
#
"
class
=
"
dropdown-toggle
"
data-toggle
=
"
dropdown
"
>
Java
<
b
class
=
"
caret
"
>
b
>
a
>
<
ul
class
=
"
dropdown-menu
"
>
<
li
>
<
a
href
=
"
#
"
>
jmeter
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
EJB
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
Jasper Report
a
>
li
>
<
li
class
=
"
divider
"
>
li
>
<
li
>
<
a
href
=
"
#
"
>
分离的链接
a
>
li
>
<
li
class
=
"
divider
"
>
li
>
<
li
>
<
a
href
=
"
#
"
>
另一个分离的链接
a
>
li
>
ul
>
li
>
ul
>
div
>
div
>
nav
>
尝试一下 »
结果如下所示:
固定到底部
如果您想要让导航栏固定在页面的底部,请向 .navbar class 添加 class .navbar-fixed-bottom。下面的实例演示了这点:
实例
<
nav
class
=
"
navbar navbar-default navbar-fixed-bottom
"
role
=
"
navigation
"
>
<
div
class
=
"
container-fluid
"
>
<
div
class
=
"
navbar-header
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
菜鸟教程
a
>
div
>
<
div
>
<
ul
class
=
"
nav navbar-nav
"
>
<
li
class
=
"
active
"
>
<
a
href
=
"
#
"
>
iOS
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
SVN
a
>
li
>
<
li
class
=
"
dropdown
"
>
<
a
href
=
"
#
"
class
=
"
dropdown-toggle
"
data-toggle
=
"
dropdown
"
>
Java
<
b
class
=
"
caret
"
>
b
>
a
>
<
ul
class
=
"
dropdown-menu
"
>
<
li
>
<
a
href
=
"
#
"
>
jmeter
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
EJB
a
>
li
>
<
li
>
<
a
href
=
"
#
"
>
Jasper Report
a
>
li
>
<
li
class
=
"
divider
"
>
<
当前文章:创新互联Bootstrap教程:Bootstrap导航栏
分享URL:http://www.mswzjz.cn/qtweb/news7/468057.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
贝锐智能