Components (10): Navbar
Component suite for navigation bars.
nav.navbar
.navbar-expand-md (expands/collapses on md breakpoint).navbar-light.bg-light ⇒ Color schemesa.navbar-brand
button.navbar-toggler (displays on collapsed)
span.navbar-toggler-icondiv.collapse.navbar-collapse (displays on expanded ⇒ Toggler )
ul.navbar-nav.mr-auto
form.form-inline
input.form-controlbutton.btn.btn-outline-success(a|span).navbar-brandnav.navbar
(a|span).navbar-brand Attribute
a ) Attribute href="..."Navbar(a|span).navbar-brand.h1(a|span).navbar-brand.h1.mb-0 Attributes
.h1 (see Typography - Headings ).mb-0 (cancels bottom margin for heading)(a|span).navbar-brand
img Attributes
href="..."width="..."height="..."alt="..."(a|span).navbar-brand
img Attributes
.d-inline-block (⇒ Display ).align-top (⇒ Vertical alignment ) Bootstrap (whitespace required between the image)A navbar usually has a nav and also behaves responsively with a toggler. A nav is set inside of a collapsing wrapper. A toggler collapses a nav when the viewport width is smaller than the specified breakpoint.
uldiv.navbar-nav (can be built with fewer DOM hierarchy)Inline forms form.form-inline can be used within a navbar.
form.form-inline
input.form-control Attributes
.mr-sm-2type="search"placeholder="Search"aria-label="Search"button.btn.btn-outline-success Attributes
.my-2.my-sm-0type="submit"Search.justify-content-between to the bar (see Flex )
form.form-inline
div.input-group
form.form-inline
button.btn.btn-outline-success Attribute
type="button"Main buttonbutton.btn.btn-sm.btn-outline-secondary Attributes
.ml-2 (⇒ Spacing )type="button"Smaller buttonUse span.navbar-text for the plain text inside the navbar.
Set both the text color scheme and the background color.
.navbar-(light|dark)
.navbar-light : Text color scheme for bright background.navbar-dark : Text color scheme for dark background.bg-(primary|secondary|...)
style="backgroudnd-color: lightblue;"nav.navbar.navbar-dark.bg-dark
nav.navbar.navbar-dark.bg-primary
nav.navbar.navbar-light + Attribute style="background-color: #e3f2fd;"
Setting a navbar outside the container (usually as a child of body ) displays as 100% width to the viewport (the example below).
All other navbars in this page are set as children of a container div.container. Their widths are responsive to the viewport and display center-aligned.
The last example looks same as above. But it sets extra padding before a brand on lg or greater.
Structurenav.navbar
.navbar-expand-lg (expands/collapses with lg breakpoint)div.container
NavbarA container sets horizontal 15px paddings (gutters) on left and right as default. But a container inside a navbar with a collapted state removes gutters.
position: relativeposition: fixed to the topposition: fixed to the bottomposition: stickynav.navbar (scrolls relative to the page)nav.navbar.fixed-topnav.navbar.fixed-bottomnav.navbar.sticky-topA navbar acts responsively with a toggler.
nav.navbar.navbar-light.bg-light Attribute
.navbar-expand-md (expands/collapses on md breakpoint)a.navbar-brand ...button.navbar-toggler (displays on collapsed) Attributes
type="button"data-toggle="collapse"data-target="#toggler-demo" (sets the collasping wrapper)aria-controls="toggler-demo"aria-expanded="false"aria-label="Toggle navigation"span.navbar-toggler-icondiv.collapse.navbar-collapse (displays on expanded) Attribute
Toggler breakpoint is specified with .navbar-expand-(sm|md|lg|xl). To set navbar always expanded, use .navbar-expand. The example below is identical to above but replacing .nabvar-expand-md to .nabvar-expand (does not collapse).
Toggler also can be used to expand/collapse a content outside a navbar. See the example below.
Structurediv.collapse Attribute
id="{wrapper-id}"div.bg-dark.p-4
nav.navbar.navbar-dark.bg-dark (always collapsed)
button.navbar-toggler Attributes
type="button"data-toggle="collapse"data-target="#{wrapper-id}"span.navbar-toggler-icon