导航栏一般放在页面的顶部。
公司主营业务:成都做网站、成都网站设计、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联公司推出江山免费做网站回馈大家。
我们可以使用 .navbar 类来创建一个标准的导航栏,后面紧跟: .navbar-expand-xxl|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-xxl|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)。
提示: 对于暗色背景 .navbar-dark 需要设置文本颜色为浅色的,对于浅色背景 .navbar-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-bs-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-bs-toggle
=
"
collapse
"
data-bs-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-bs-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
>
尝试一下 »
导航栏的表单