Movatterモバイル変換


[0]ホーム

URL:


Framework:


Hire Us Get CoreUI PRO all-access

Bootstrap 5 Navbar

Navbar

Documentation and examples for CoreUI for Bootstrap’s powerful, responsive navigation header, the navbar. Includes support for branding, navigation, and more, including support for our collapse plugin.

🤖 Looking for the LLM-optimized version?View llm.md

Other frameworks

CoreUI components are available as native Angular, React, and Vue components. To learn more please visit the following pages.

On this page

How it works

Here’s what you need to know before getting started with the navbar:

  • Navbars require a wrapping.navbar with.navbar-expand{-sm|-md|-lg|-xl|-xxl} for responsive collapsing andcolor scheme classes.
  • Navbars and their contents are fluid by default. Change thecontainer to limit their horizontal width in different ways.
  • Use ourspacing andflex utility classes for controlling spacing and alignment within navbars.
  • Navbars are responsive by default, but you can easily modify them to change that. Responsive behavior depends on our Collapse JavaScript plugin.
  • Ensure accessibility by using a<nav> element or, if using a more generic element such as a<div>, add arole="navigation" to every navbar to explicitly identify it as a landmark region for users of assistive technologies.
  • Indicate the current item by usingaria-current="page" for the current page oraria-current="true" for the current item in a set.
  • Navbars can be themed with CSS variables that are scoped to the.navbar base class..navbar-light has been deprecated and.navbar-dark has been rewritten to override CSS variables instead of adding additional styles.
This component's animation effect relies on theprefers-reduced-motion media query. For more information, refer to thereduced motion section of our accessibility documentation.

Supported content

Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:

  • .navbar-brand for your company, product, or project name.
  • .navbar-nav for a full-height and lightweight navigation (including support for dropdowns).
  • .navbar-toggler for use with our collapse plugin and othernavigation toggling behaviors.
  • Flex and spacing utilities for any form controls and actions.
  • .navbar-text for adding vertically centered strings of text.
  • .collapse.navbar-collapse for grouping and hiding navbar contents by a parent breakpoint.
  • Add an optional.navbar-scroll to set amax-height andscroll expanded navbar content.

Here’s an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at thelg (large) breakpoint.

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarSupportedContent"aria-controls="navbarSupportedContent"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarSupportedContent"><ulclass="navbar-nav me-auto mb-2 mb-lg-0"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item dropdown"><aclass="nav-link dropdown-toggle"href="#"role="button"data-coreui-toggle="dropdown"aria-expanded="false">            Dropdown</a><ulclass="dropdown-menu"><li><aclass="dropdown-item"href="#">Action</a></li><li><aclass="dropdown-item"href="#">Another action</a></li><li><hrclass="dropdown-divider"></li><li><aclass="dropdown-item"href="#">Something else here</a></li></ul></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></div></nav>

This example usesbackground (bg-body-tertiary") andspacing (me-auto,mb-2,mb-lg-0,me-2) utility classes.

Brand

The.navbar-brand can be applied to most elements, but an anchor works best, as some elements might require utility classes or custom styles.

Text

Add your text within an element with the.navbar-brand class.

html
<!-- As a link --><navclass="navbar bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar</a></div></nav><!-- As a heading --><navclass="navbar bg-body-tertiary"><divclass="container-fluid"><spanclass="navbar-brand mb-0 h1">Navbar</span></div></nav>

Image

You can replace the text within the.navbar-brand with an<img>.

html
<navclass="navbar bg-body-tertiary"><divclass="container"><aclass="navbar-brand"href="#"><imgsrc="/assets/brand/coreui-signet.svg"alt=""width="22"height="24"></a></div></nav>

Image and text

You can also make use of some additional utilities to add an image and text at the same time. Note the addition of.d-inline-block and.align-text-top on the<img>.

html
<navclass="navbar bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#"><imgsrc="/assets/brand/coreui-signet.svg"alt=""width="22"height="24"class="d-inline-block align-top">      CoreUI</a></div></nav>

Nav

Navbar navigation links build on our.nav options with their own modifier class and require the use oftoggler classes for proper responsive styling.Navigation in navbars will also grow to occupy as much horizontal space as possible to keep your navbar contents securely aligned.

Add the.active class on.nav-link to indicate the current page.

Please note that you should also add thearia-current attribute on the active.nav-link.

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarNav"aria-controls="navbarNav"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarNav"><ulclass="navbar-nav"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Features</a></li><liclass="nav-item"><aclass="nav-link"href="#">Pricing</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul></div></div></nav>

And because we use classes for our navs, you can avoid the list-based approach entirely if you like.

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarNavAltMarkup"aria-controls="navbarNavAltMarkup"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarNavAltMarkup"><divclass="navbar-nav"><aclass="nav-link active"aria-current="page"href="#">Home</a><aclass="nav-link"href="#">Features</a><aclass="nav-link"href="#">Pricing</a><aclass="nav-link disabled"aria-disabled="true">Disabled</a></div></div></div></nav>

You can also use dropdowns in your navbar. Dropdown menus require a wrapping element for positioning, so be sure to use separate and nested elements for.nav-item and.nav-link as shown below.

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarNavDropdown"aria-controls="navbarNavDropdown"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarNavDropdown"><ulclass="navbar-nav"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Features</a></li><liclass="nav-item"><aclass="nav-link"href="#">Pricing</a></li><liclass="nav-item dropdown"><aclass="nav-link dropdown-toggle"href="#"role="button"data-coreui-toggle="dropdown"aria-expanded="false">            Dropdown link</a><ulclass="dropdown-menu"><li><aclass="dropdown-item"href="#">Action</a></li><li><aclass="dropdown-item"href="#">Another action</a></li><li><aclass="dropdown-item"href="#">Something else here</a></li></ul></li></ul></div></div></nav>

Forms

Place various form controls and components within a navbar:

html
<navclass="navbar bg-body-tertiary"><divclass="container-fluid"><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></nav>

Immediate child elements of.navbar use flex layout and will default tojustify-content: space-between. Use additionalflex utilities as needed to adjust this behavior.

html
<navclass="navbar bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand">Navbar</a><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></nav>

Input groups work, too. If your navbar is an entire form, or mostly a form, you can use the<form> element as the container and save some HTML.

html
<navclass="navbar bg-body-tertiary"><formclass="container-fluid"><divclass="input-group"><spanclass="input-group-text"id="basic-addon1">@</span><inputtype="text"class="form-control"placeholder="Username"aria-label="Username"aria-describedby="basic-addon1"></div></form></nav>

Various buttons are supported as part of these navbar forms, too. This is also a great reminder that vertical alignment utilities can be used to align different sized elements.

html
<navclass="navbar bg-body-tertiary"><formclass="container-fluid justify-content-start"><buttonclass="btn btn-outline-success me-2"type="button">Main button</button><buttonclass="btn btn-sm btn-outline-secondary"type="button">Smaller button</button></form></nav>

Text

Navbars may contain bits of text with the help of.navbar-text. This class adjusts vertical alignment and horizontal spacing for strings of text.

html
<navclass="navbar bg-body-tertiary"><divclass="container-fluid"><spanclass="navbar-text">      Navbar text with an inline element</span></div></nav>

Mix and match with other components and utilities as needed.

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar w/ text</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarText"aria-controls="navbarText"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarText"><ulclass="navbar-nav me-auto mb-2 mb-lg-0"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Features</a></li><liclass="nav-item"><aclass="nav-link"href="#">Pricing</a></li></ul><spanclass="navbar-text">        Navbar text with an inline element</span></div></div></nav>

Color schemes

New dark navbars in v5.0.0 — We’ve deprecated.navbar-dark in favor of the newdata-coreui-theme="dark". Adddata-coreui-theme="dark" to the.navbar to enable a component-specific color mode.Learn more about our color modes.


New in v4.2.6 — Navbar theming is now powered by CSS variables and.navbar-light has been deprecated. CSS variables are applied to.navbar, defaulting to the “light” appearance, and can be overridden with.navbar-dark.

Navbar themes are easier than ever thanks to CoreUI for Bootstrap’s combination of Sass and CSS variables. The default is our “light navbar” for use with light background colors, but you can also applydata-coreui-theme="dark" for dark background colors. Then, customize with.bg-* utilities.

<navclass="navbar bg-dark border-bottom border-body"data-coreui-theme="dark"><!-- Navbar content --></nav><navclass="navbar bg-primary"data-coreui-theme="dark"><!-- Navbar content --></nav><navclass="navbar"style="background-color: #e3f2fd;"><!-- Navbar content --></nav>

Containers

Although it’s not required, you can wrap a navbar in a.container to center it on a page–though note that an inner container is still required. Or you can add a container inside the.navbar to only center the contents of afixed or static top navbar.

html
<divclass="container"><navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar</a></div></nav></div>

Use any of the responsive containers to change how wide the content in your navbar is presented.

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-md"><aclass="navbar-brand"href="#">Navbar</a></div></nav>

Placement

Use ourposition utilities to place navbars in non-static positions. Choose from fixed to the top, fixed to the bottom, stickied to the top (scrolls with the page until it reaches the top, then stays there), or stickied to the bottom (scrolls with the page until it reaches the bottom, then stays there).

Fixed navbars useposition: fixed, meaning they’re pulled from the normal flow of the DOM and may require custom CSS (e.g.,padding-top on the<body>) to prevent overlap with other elements.

html
<navclass="navbar bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Default</a></div></nav>
html
<navclass="navbar fixed-top bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Fixed top</a></div></nav>
html
<navclass="navbar fixed-bottom bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Fixed bottom</a></div></nav>
html
<navclass="navbar sticky-top bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Sticky top</a></div></nav>
html
<navclass="navbar sticky-bottom bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Sticky bottom</a></div></nav>

Scrolling

Add.navbar-nav-scroll to a.navbar-nav (or other navbar sub-component) to enable vertical scrolling within the toggleable contents of a collapsed navbar. By default, scrolling kicks in at75vh (or 75% of the viewport height), but you can override that with the local CSS custom propertynavbar-height or custom styles. At larger viewports when the navbar is expanded, content will appear as it does in a default navbar.

Please note that this behavior comes with a potential drawback ofoverflow—when settingoverflow-y: auto (required to scroll the content here),overflow-x is the equivalent ofauto, which will crop some horizontal content.

Here’s an example navbar using.navbar-nav-scroll withstyle="scroll-height: 100px;", with some extra margin utilities for optimum spacing.

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar scroll</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarScroll"aria-controls="navbarScroll"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarScroll"><ulclass="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll"style="scroll-height: 100px;"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item dropdown"><aclass="nav-link dropdown-toggle"href="#"role="button"data-coreui-toggle="dropdown"aria-expanded="false">            Link</a><ulclass="dropdown-menu"><li><aclass="dropdown-item"href="#">Action</a></li><li><aclass="dropdown-item"href="#">Another action</a></li><li><hrclass="dropdown-divider"></li><li><aclass="dropdown-item"href="#">Something else here</a></li></ul></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Link</a></li></ul><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></div></nav>

Responsive behaviors

Navbars can use.navbar-toggler,.navbar-collapse, and.navbar-expand{-sm|-md|-lg|-xl|-xxl} classes to determine when their content collapses behind a button. In combination with other utilities, you can easily choose when to show or hide particular elements.

For navbars that never collapse, add the.navbar-expand class on the navbar. For navbars that always collapse, don’t add any.navbar-expand class.

Toggler

Navbar togglers are left-aligned by default, but should they follow a sibling element like a.navbar-brand, they’ll automatically be aligned to the far right. Reversing your markup will reverse the placement of the toggler. Below are examples of different toggle styles.

With no.navbar-brand shown at the smallest breakpoint:

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarTogglerDemo01"aria-controls="navbarTogglerDemo01"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarTogglerDemo01"><aclass="navbar-brand"href="#">Hidden brand</a><ulclass="navbar-nav me-auto mb-2 mb-lg-0"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></div></nav>

With a brand name shown on the left and toggler on the right:

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><aclass="navbar-brand"href="#">Navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarTogglerDemo02"aria-controls="navbarTogglerDemo02"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><divclass="collapse navbar-collapse"id="navbarTogglerDemo02"><ulclass="navbar-nav me-auto mb-2 mb-lg-0"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></div></nav>

With a toggler on the left and brand name on the right:

html
<navclass="navbar navbar-expand-lg bg-body-tertiary"><divclass="container-fluid"><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarTogglerDemo03"aria-controls="navbarTogglerDemo03"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button><aclass="navbar-brand"href="#">Navbar</a><divclass="collapse navbar-collapse"id="navbarTogglerDemo03"><ulclass="navbar-nav me-auto mb-2 mb-lg-0"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></div></nav>

External content

Sometimes you want to use the collapse plugin to trigger a container element for content that structurally sits outside of the.navbar . Because our plugin works on theid anddata-coreui-target matching, that’s easily done!

Collapsed content
Toggleable via the navbar brand.
html
<divclass="collapse"id="navbarToggleExternalContent"><divclass="bg-dark p-4"><h5class="text-white h4">Collapsed content</h5><spanclass="text-body-secondary">Toggleable via the navbar brand.</span></div></div><navclass="navbar navbar-dark bg-dark"><divclass="container-fluid"><buttonclass="navbar-toggler"type="button"data-coreui-toggle="collapse"data-coreui-target="#navbarToggleExternalContent"aria-controls="navbarToggleExternalContent"aria-expanded="false"aria-label="Toggle navigation"><spanclass="navbar-toggler-icon"></span></button></div></nav>

When you do this, we recommend including additional JavaScript to move the focus programmatically to the container when it is opened. Otherwise, keyboard users and users of assistive technologies will likely have a hard time finding the newly revealed content - particularly if the container that was opened comesbefore the toggler in the document’s structure. We also recommend making sure that the toggler has thearia-controls attribute, pointing to theid of the content container. In theory, this allows assistive technology users to jump directly from the toggler to the container it controls–but support for this is currently quite patchy.

Offcanvas

Transform your expanding and collapsing navbar into an offcanvas drawer with theoffcanvas component. We extend both the offcanvas default styles and use our.navbar-expand-* classes to create a dynamic and flexible navigation sidebar.

In the example below, to create an offcanvas navbar that is always collapsed across all breakpoints, omit the.navbar-expand-* class entirely.

html
<navclass="navbar bg-body-tertiary"fixed-top"><divclass="container-fluid"><aclass="navbar-brand"href="#">Offcanvas navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="offcanvas"data-coreui-target="#offcanvasNavbar"aria-controls="offcanvasNavbar"><spanclass="navbar-toggler-icon"></span></button><divclass="offcanvas offcanvas-end"tabindex="-1"id="offcanvasNavbar"aria-labelledby="offcanvasNavbarLabel"><divclass="offcanvas-header"><h5class="offcanvas-title"id="offcanvasNavbarLabel">Offcanvas</h5><buttontype="button"class="btn-close text-reset"data-coreui-dismiss="offcanvas"aria-label="Close"></button></div><divclass="offcanvas-body"><ulclass="navbar-nav justify-content-end flex-grow-1 pe-3"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item dropdown"><aclass="nav-link dropdown-toggle"href="#"role="button"data-coreui-toggle="dropdown"aria-expanded="false">              Dropdown</a><ulclass="dropdown-menu"><li><aclass="dropdown-item"href="#">Action</a></li><li><aclass="dropdown-item"href="#">Another action</a></li><li><hrclass="dropdown-divider"></li><li><aclass="dropdown-item"href="#">Something else here</a></li></ul></li></ul><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-outline-success"type="submit">Search</button></form></div></div></div></nav>

To create an offcanvas navbar that expands into a normal navbar at a specific breakpoint likelg, use.navbar-expand-lg.

<navclass="navbar navbar-expand-lg bg-body-tertiary"fixed-top"><aclass="navbar-brand"href="#">Offcanvas navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="offcanvas"data-coreui-target="#navbarOffcanvasLg"aria-controls="navbarOffcanvasLg"><spanclass="navbar-toggler-icon"></span></button><divclass="offcanvas offcanvas-end"tabindex="-1"id="navbarOffcanvasLg"aria-labelledby="navbarOffcanvasLgLabel">    ...</div></nav>

When using offcanvas in a dark navbar, be aware that you may need to have a dark background on the offcanvas content to avoid the text becoming illegible. In the example below, we add.navbar-dark and.bg-dark to the.navbar,.text-bg-dark to the.offcanvas,.dropdown-menu-dark to.dropdown-menu, and.btn-close-white to.btn-close for proper styling with a dark offcanvas.

html
<navclass="navbar navbar-dark bg-dark fixed-top"><divclass="container-fluid"><aclass="navbar-brand"href="#">Offcanvas dark navbar</a><buttonclass="navbar-toggler"type="button"data-coreui-toggle="offcanvas"data-coreui-target="#offcanvasDarkNavbar"aria-controls="offcanvasDarkNavbar"><spanclass="navbar-toggler-icon"></span></button><divclass="offcanvas offcanvas-end text-bg-dark"tabindex="-1"id="offcanvasDarkNavbar"aria-labelledby="offcanvasDarkNavbarLabel"><divclass="offcanvas-header"><h5class="offcanvas-title"id="offcanvasDarkNavbarLabel">Dark offcanvas</h5><buttontype="button"class="btn-close btn-close-white"data-coreui-dismiss="offcanvas"aria-label="Close"></button></div><divclass="offcanvas-body"><ulclass="navbar-nav justify-content-end flex-grow-1 pe-3"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Home</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item dropdown"><aclass="nav-link dropdown-toggle"href="#"role="button"data-coreui-toggle="dropdown"aria-expanded="false">              Dropdown</a><ulclass="dropdown-menu dropdown-menu-dark"><li><aclass="dropdown-item"href="#">Action</a></li><li><aclass="dropdown-item"href="#">Another action</a></li><li><hrclass="dropdown-divider"></li><li><aclass="dropdown-item"href="#">Something else here</a></li></ul></li></ul><formclass="d-flex"role="search"><inputclass="form-control me-2"type="search"placeholder="Search"aria-label="Search"><buttonclass="btn btn-success"type="submit">Search</button></form></div></div></div></nav>

Customizing

CSS variables

Navbars use local CSS variables on.navbar for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.

scss/_navbar.scss
--cui-navbar-padding-x:#{if($navbar-padding-x==null,0,$navbar-padding-x)};--cui-navbar-padding-y:#{$navbar-padding-y};--cui-navbar-color:#{$navbar-light-color};--cui-navbar-hover-color:#{$navbar-light-hover-color};--cui-navbar-disabled-color:#{$navbar-light-disabled-color};--cui-navbar-active-color:#{$navbar-light-active-color};--cui-navbar-brand-padding-y:#{$navbar-brand-padding-y};--cui-navbar-brand-margin-end:#{$navbar-brand-margin-end};--cui-navbar-brand-font-size:#{$navbar-brand-font-size};--cui-navbar-brand-color:#{$navbar-light-brand-color};--cui-navbar-brand-hover-color:#{$navbar-light-brand-hover-color};--cui-navbar-nav-link-padding-x:#{$navbar-nav-link-padding-x};--cui-navbar-toggler-padding-y:#{$navbar-toggler-padding-y};--cui-navbar-toggler-padding-x:#{$navbar-toggler-padding-x};--cui-navbar-toggler-font-size:#{$navbar-toggler-font-size};--cui-navbar-toggler-icon-bg:#{escape-svg($navbar-light-toggler-icon-bg)};--cui-navbar-toggler-border-color:#{$navbar-light-toggler-border-color};--cui-navbar-toggler-border-radius:#{$navbar-toggler-border-radius};--cui-navbar-toggler-focus-width:#{$navbar-toggler-focus-width};--cui-navbar-toggler-transition:#{$navbar-toggler-transition};

Some additional CSS variables are also present on.navbar-nav:

scss/_navbar.scss
--cui-nav-link-padding-x:0;--cui-nav-link-padding-y:#{$nav-link-padding-y};@include rfs($nav-link-font-size,--cui-nav-link-font-size);--cui-nav-link-font-weight:#{$nav-link-font-weight};--cui-nav-link-color:var(--cui-navbar-color);--cui-nav-link-hover-color:var(--cui-navbar-hover-color);--cui-nav-link-disabled-color:var(--cui-navbar-disabled-color);

SASS variables

Variables for all navbars:

scss/_variables.scss
$navbar-padding-y:$spacer*.5;$navbar-padding-x:null;$navbar-nav-link-padding-x:.5rem;$navbar-brand-font-size:$font-size-lg;// Compute the navbar-brand padding-y so the navbar-brand will have the same height as navbar-text and nav-link$nav-link-height:$font-size-base*$line-height-base+$nav-link-padding-y*2;$navbar-brand-height:$navbar-brand-font-size*$line-height-base;$navbar-brand-padding-y:($nav-link-height-$navbar-brand-height)*.5;$navbar-brand-margin-end:1rem;$navbar-toggler-padding-y:.25rem;$navbar-toggler-padding-x:.75rem;$navbar-toggler-font-size:$font-size-lg;$navbar-toggler-border-radius:$btn-border-radius;$navbar-toggler-focus-width:$btn-focus-width;$navbar-toggler-transition:box-shadow.15sease-in-out;$navbar-light-color:rgba(var(--#{$prefix}emphasis-color-rgb),.65);$navbar-light-hover-color:rgba(var(--#{$prefix}emphasis-color-rgb),.8);$navbar-light-active-color:rgba(var(--#{$prefix}emphasis-color-rgb),1);$navbar-light-disabled-color:rgba(var(--#{$prefix}emphasis-color-rgb),.3);$navbar-light-icon-color:rgba($body-color,.75);$navbar-light-toggler-icon-bg:url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-light-icon-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");$navbar-light-toggler-border-color:rgba(var(--#{$prefix}emphasis-color-rgb),.15);$navbar-light-brand-color:$navbar-light-active-color;$navbar-light-brand-hover-color:$navbar-light-active-color;

Variables for thedark navbar:

scss/_variables.scss
$navbar-dark-color:rgba($white,.55);$navbar-dark-hover-color:rgba($white,.75);$navbar-dark-active-color:$white;$navbar-dark-disabled-color:rgba($white,.25);$navbar-dark-icon-color:$navbar-dark-color;$navbar-dark-toggler-icon-bg:url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-dark-icon-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");$navbar-dark-toggler-border-color:rgba($white,.1);$navbar-dark-toggler-border-color:rgba($white,.1);$navbar-dark-brand-color:$navbar-dark-active-color;$navbar-dark-brand-hover-color:$navbar-dark-active-color;

SASS loop

Responsive navbar expand/collapse classes (e.g.,.navbar-expand-lg) are combined with the$breakpoints map and generated through a loop inscss/_navbar.scss.

scss/_navbar.scss
// Generate series of `.navbar-expand-*` responsive classes for configuring// where your navbar collapses..navbar-expand{@each$breakpointinmap.keys($grid-breakpoints){$next:breakpoint-next($breakpoint,$grid-breakpoints);$infix:breakpoint-infix($next,$grid-breakpoints);// stylelint-disable-next-line scss/selector-no-union-class-name&#{$infix}{@include media-breakpoint-up($next){flex-wrap:nowrap;justify-content:flex-start;.navbar-nav{flex-direction:row;.dropdown-menu{position:absolute;}.nav-link{padding-right:var(--#{$prefix}navbar-nav-link-padding-x);padding-left:var(--#{$prefix}navbar-nav-link-padding-x);}}.navbar-nav-scroll{overflow:visible;}.navbar-collapse{display:flex!important;// stylelint-disable-line declaration-no-importantflex-basis:auto;}.navbar-toggler{display:none;}.offcanvas{// stylelint-disable declaration-no-importantposition:static;z-index:auto;flex-grow:1;width:auto!important;height:auto!important;visibility:visible!important;background-color:transparent!important;border:0!important;transform:none!important;@include box-shadow(none);@include transition(none);// stylelint-enable declaration-no-important.offcanvas-header{display:none;}.offcanvas-body{display:flex;flex-grow:0;padding:0;overflow-y:visible;}}}}}}

CoreUI vs Bootstrap

While this Navbar component is fully compatible with Bootstrap and follows its core principles, CoreUI delivers a more complete solution for modern app development.

What sets CoreUI apart from Bootstrap?

  • Fully compatible with Bootstrap – Built directly on Bootstrap, all classes and behaviors work as expected.
  • 🧠Framework-native versions – CoreUI provides dedicated libraries forReact.js,Vue.js, andAngular, unlike Bootstrap which relies on third-party plugins for JavaScript frameworks.
  • 👨‍💻Maintained by a full-time team – CoreUI is developed as a professional product, not a volunteer-driven project.
  • 📦More built-in components – Includes additional ready-to-use components like range sliders, multi-selects, steppers, etc.
  • 🛠️Sass Modules support today – CoreUI already supports Sass Modules, which are planned for Bootstrap 6.
  • 🌍Better LTR/RTL support – Uses modern CSS logical properties for seamless bidirectional layout support.
  • 🔒LTS (Long-Term Support) – Bootstrap now offers LTS only via paid third parties like HeroDevs, while CoreUI continues to offer long-term support natively and for free.

Whether you’re building internal tools, dashboards, or SaaS platforms — CoreUI combines the familiarity of Bootstrap with a more powerful, scalable, and production-ready ecosystem.

👉Explore CoreUI Bootstrap Components
👉Compare CoreUI vs Bootstrap


[8]ページ先頭

©2009-2025 Movatter.jp