Skip to content Skip to sidebar Skip to footer

Changing Bootstrap 4 Navbar Collapse Breakpoint

Changing the navbar breakpoint in Bootstrap 4 is a straightforward process with the use of the “navbar-expand-*” classes. These classes determine when the mobile menu should be displayed based on screen size.

For example, by adding the class “navbar-expand-sm” to the <nav> element, the mobile menu will appear on extra small screens with a width less than 576 pixels. Similarly, “navbar-expand-md”, “navbar-expand-lg”, and “navbar-expand-xl” control the visibility of the mobile menu on small, medium, and large screens respectively.

To always display the mobile menu regardless of screen size, exclude any “navbar-expand-*” classes. On the other hand, if you want to create a custom breakpoint at a specific width (e.g., 1024), you can utilize CSS to achieve this. The code snippet provided demonstrates how to accomplish this customization.

Overall, understanding and implementing these techniques will allow you to effectively control when and how your navbar responds to different screen sizes. For a visual representation of all six navbar states mentioned above, please refer to this demo example: [bootstrap-4-navbar-example-link].navbar-expand-sm = mobile menu on xs screens <576px

  • navbar-expand-md = mobile menu on sm screens <768px
  • navbar-expand-lg = mobile menu on md screens <992px
  • navbar-expand-xl = mobile menu on lg screens <1200px
  • navbar-expand = never use mobile menu
  • (no expand class) = always use mobile menu

If you exclude navbar-expand-* the mobile menu will be used at all widths. Here’s a demo of all 6 navbar states: Bootstrap 4 Navbar Example

@media (min-width: 1024){

    .navbar-expand-custom {

        flex-direction: row;

        flex-wrap: nowrap;

        justify-content: flex-start;

    }

    .navbar-expand-custom .navbar-nav {

        flex-direction: row;

    }

    .navbar-expand-custom .dropdown-menu {

        position: absolute;

    }

    .navbar-expand-custom .nav-link {

        padding-right: .5rem;

        padding-left: .5rem;

    }

    .navbar-expand-custom > .container {

        flex-wrap: nowrap;

    }

    .navbar-expand-custom .navbar-collapse {

        display: flex!important;

        flex-basis: auto;

    }

    .navbar-expand-custom .navbar-toggler {

        display: none;

    }

}

If you use it on bootstrap 3 Read this : Changing Bootstrap 3 Navbar Collapse Breakpoint 992: A Quick Guide

I hope this code is helpful for you. If it helps and you find it useful, please write a comment to let us know. You can also buy me a coffee as a gesture of appreciation. Thank you!

What's your reaction?
0Smile0Lol0Wow0Love0Sad0Angry

Leave a comment