"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Keep Navbar Items Visible Even When the Navbar Collapses in Bootstrap 4?

How to Keep Navbar Items Visible Even When the Navbar Collapses in Bootstrap 4?

Published on 2024-11-02
Browse:411

How to Keep Navbar Items Visible Even When the Navbar Collapses in Bootstrap 4?

Bootstrap 4: Persistent Navbar Items Outside Collapsed Container

Navigating a website can be frustrating when important links, such as social media icons, disappear when the navbar collapses on smaller screens. Fortunately, Bootstrap 4 offers an elegant solution to keep certain navbar items visible even when the menu is collapsed.

Problem

The issue arises when the navbar is set to collapse when the screen width becomes narrow. This behavior is controlled by the .collapse class. By default, all elements within the .collapse container are hidden when the collapse is activated.

Solution

To keep certain navbar items from disappearing with the collapse, simply move them outside the .collapse container. This can be achieved using the order-* utility classes to adjust the flexbox order of the elements.

Code Example

In this example, the social media icons are placed within a container outside the .collapse element. The d-flex and order-* classes ensure that the icons remain in the correct order and position when the navbar is collapsed.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3