VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-navbar-responsive-behaviors/

⇱ Bootstrap 5 Navbar Responsive Behaviors - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Navbar Responsive Behaviors

Last Updated : 30 Dec, 2022

Bootstrap 5 Navbar Responsive behaviors help us determine when the content will hide behind a button. For this, we use .navbar-toggler, .navbar-collapse, .navbar-expand{-sm|-md|-lg|-xl|-xxl} classes. Add .navbar-expand class so that the navbar never collapses and for the navbar to collapse never add .navbar-expand class.

Bootstrap 5 Navbar Responsive behaviors:

  • Toggler: The navbar toggler is left-aligned by default but by reversing our code, the placement of togglers will also be reversed. Toggler and brand name positions can be interchanged.
  • External Content: Sometimes you need to collapse the button to access some content that is outside of the container. With the help of id and data-bs-target matching, we can easily do it. Including additional JavaScript is recommended for moving focus on the navbar when it is opened.

Example 1: In this example brand name is shown on the left and the toggle on right.

Output:

👁 Bootstrap 5 Navbar Responsive Behaviors
Bootstrap 5 Navbar Responsive Behaviors

Example 2: In this example, Bootstrap 5 Navbar external content is shown.

Output:

👁 Bootstrap 5 Navbar Responsive Behaviors
Bootstrap 5 Navbar Responsive Behaviors

References: https://getbootstrap.com/docs/5.0/components/navbar/#responsive-behaviors

Comment

Explore