导航栏一般放在页面的顶部。
成都创新互联是一家集网站建设,保靖企业网站建设,保靖品牌网站建设,网站定制,保靖网站建设报价,网络营销,网络优化,保靖网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
我们可以使用 .navbar 类来创建一个标准的导航栏,后面紧跟: .navbar-expand-xl|lg|md|sm 类来创建响应式的导航栏 (大屏幕水平铺开,小屏幕垂直堆叠)。
导航栏上的选项可以使用
<
nav
class
=
"
navbar navbar-expand-sm bg-light
"
>
<
ul
class
=
"
navbar-nav
"
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 1
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 2
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 3
a
>
li
>
ul
>
nav
>
尝试一下 »
通过删除 .navbar-expand-xl|lg|md|sm 类来创建垂直导航栏:
<
nav
class
=
"
navbar bg-light
"
>
<
ul
class
=
"
navbar-nav
"
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 1
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 2
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 3
a
>
li
>
ul
>
nav
>
尝试一下 »
通过添加 .justify-content-center 类来创建居中对齐的导航栏:
<
nav
class
=
"
navbar navbar-expand-sm bg-light justify-content-center
"
>
...
nav
>
尝试一下 »
可以使用以下类来创建不同颜色导航栏:.bg-primary, .bg-success, .bg-info, .bg-warning, .bg-danger, .bg-secondary, .bg-dark 和 .bg-light)。
提示: 对于暗色背景需要设置文本颜色为浅色的,对于浅色背景需要设置文本颜色为深色的。
<
nav
class
=
"
navbar navbar-expand-sm bg-light navbar-light
"
>
<
ul
class
=
"
navbar-nav
"
>
<
li
class
=
"
nav-item active
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Active
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link disabled
"
href
=
"
#
"
>
Disabled
a
>
li
>
ul
>
nav
>
<
nav
class
=
"
navbar navbar-expand-sm bg-dark navbar-dark
"
>
...
nav
>
<
nav
class
=
"
navbar navbar-expand-sm bg-primary navbar-dark
"
>
...
nav
>
尝试一下 »
激活和禁用状态: 可以在 元素上添加 .active 类来高亮显示选中的选项。 .disabled 类用于设置该链接是不可点击的。
.navbar-brand 类用于高亮显示品牌/Logo:
<
nav
class
=
"
navbar navbar-expand-sm bg-dark navbar-dark
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
Logo
a
>
...
nav
>
尝试一下 »
可以使用 .navbar-brand 类来设置图片自适应导航栏。
<
nav
class
=
"
navbar navbar-expand-sm bg-dark navbar-dark
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
<
img
decoding
=
"
async
"
src
=
"
bird.jpg
"
alt
=
"
Logo
"
style
=
"
width:40px;
"
>
a
>
...
nav
>
尝试一下 »
通常,小屏幕上我们都会折叠导航栏,通过点击来显示导航选项。
要创建折叠导航栏,可以在按钮上添加 class="navbar-toggler", data-toggle="collapse" 与 data-target="#thetarget" 类。然后在设置了 class="collapse navbar-collapse" 类的 div 上包裹导航内容(链接), div 元素上的 id 匹配按钮 data-target 的上指定的 id:
<
nav
class
=
"
navbar navbar-expand-md bg-dark navbar-dark
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
Navbar
a
>
<
button
class
=
"
navbar-toggler
"
type
=
"
button
"
data-toggle
=
"
collapse
"
data-target
=
"
#collapsibleNavbar
"
>
<
span
class
=
"
navbar-toggler-icon
"
>
span
>
button
>
<
div
class
=
"
collapse navbar-collapse
"
id
=
"
collapsibleNavbar
"
>
<
ul
class
=
"
navbar-nav
"
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link
a
>
li
>
ul
>
div
>
nav
>
尝试一下 »
导航栏上可以设置下拉菜单:
<
nav
class
=
"
navbar navbar-expand-sm bg-dark navbar-dark
"
>
<
a
class
=
"
navbar-brand
"
href
=
"
#
"
>
Logo
a
>
<
ul
class
=
"
navbar-nav
"
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 1
a
>
li
>
<
li
class
=
"
nav-item
"
>
<
a
class
=
"
nav-link
"
href
=
"
#
"
>
Link 2
a
>
li
>
<
li
class
=
"
nav-item dropdown
"
>
<
a
class
=
"
nav-link dropdown-toggle
"
href
=
"
#
"
id
=
"
navbardrop
"
data-toggle
=
"
dropdown
"
>
Dropdown link
a
>
<
div
class
=
"
dropdown-menu
"
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Link 1
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Link 2
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Link 3
a
>
div
>
li
>
ul
>
nav
>
尝试一下 »
导航栏的表单