Bootstrap: Customize the Navbar to Collapse on Smaller Screens with nav-side-menu feature

I have implemented a nav-side-menu in my HTML page that remains fixed at the top and left of the screen. My goal is to make it collapse to the left side and display a button with three bars when viewed on smaller screens, without disappearing completely. I want it to function similarly to how the sidebar collapses when the window is resized as shown here: . Here is the progress I have made so far:

  .nav-side-menu {
    overflow: auto;
    font-family: verdana; 
    font-size: 12px;
    font-weight: 200;
    background-color: #2e353d;
    position: fixed;
    top: 100px;
    width: 210px;
    height: 100% !important; 
    color: #033c73;   
    }
    
     .nav-side-menu .brand {
        background-color: #23282e;
        line-height: 50px;
        display: block;        
        text-align: center;
        font-size: 14px;
    }

    .nav-side-menu .toggle-btn {
        /*display: none;*/
    }

    .nav-side-menu ul,
    .nav-side-menu li {
        list-style: none;
        margin: 0px;
        line-height: 15px;
        cursor: pointer;
        padding-left: 10px;
       
    }

        .nav-side-menu ul :not(collapsed) .arrow:before,
        .nav-side-menu li :not(collapsed) .arrow:before {
            font-family: FontAwesome;
            content: "\f078";
            display: inline-block;
            padding-left: 10px;
            padding-right: 10px;
            vertical-align: middle;
            float: right;
        }

        .nav-side-menu ul .active,
        .nav-side-menu li .active {
            border-left: 3px solid #d19b3d;
            background-color: #4f5b69;
        }

        .nav-side-menu ul .sub-menu li.active,
        .nav-side-menu li .sub-menu li.active {
            color: #d19b3d;
        }

            .nav-side-menu ul .sub-menu li.active a,
            .nav-side-menu li .sub-menu li.active a {
                color: #d19b3d;
            }

                    @media (max-width: 767px) {
    .nav-side-menu {
        margin-bottom: 10px;
        margin-top: 100px;
        z-index: 10 !important; 
        display: none;  
    }

        .nav-side-menu .toggle-btn {
            display: block;
            cursor: pointer;
            position: absolute;
            right: 10px;
            top: 10px;
            z-index: 10 !important;
            padding: 3px;
            background-color: #ffffff;
            color: #000;
            width: 40px;
            text-align: center;
        }

        .brand {
            text-align: left !important;
            font-size: 22px;
             padding-left: 20px;
             line-height: 50px !important;
            }
        }

        @media (min-width: 767px) {
             .nav-side-menu .menu-list .menu-content {
              display: block;
          }
<body>
    <h1>Hello, world!</h1>

    <nav class="navbar-inverse" role="navigation">
         <div class="nav-side-menu sticky-top" style="padding-top: 100px">
                  
               <ul class="nav navbar-nav nav-pills nav-stacked">
                  <li>
                                                   
                    <a href="" class="nav-link expanded" data-toggle="collapse" style="padding-top:10px;padding-bottom:10px;font-size:15px;font-weight:bold;color:white;background-color:#2e353d;cursor:default">
                                                       Profile&nbsp;
                     </a>
                      
                      <ul class="flex-column nav">
                           <li class="nav-item">                            
                                <a style="padding-top:10px;padding-bottom:10px;font-size:15px;" class="nav-link" href="Profile/Item1">Item 1</a>
                            </li>
                             
                             <li class="nav-item">
                                 <a style="padding-top:10px;padding-bottom:10px;font-size:15px;" class="nav-link" href="Profile/Item2">Item 2</a>
                              </li>
                             <li class="nav-item">
                                  <a style="padding-top:10px;padding-bottom:10px;font-size:15px;" class="nav-link" href="Profile/Item3">Item 3</a>
                                </li>
                       
                                                <li class="nav-item">
                                                     <a style="padding-top:10px;padding-bottom:10px;font-size:15px;" class="nav-link" href="Profile/Item4">Item 4</a>
                                                 </li>
                          </ul>
                       </li>
                   </ul>
                                          </div>
                                        <div class="navbar-header" style="padding-top: 0px">
                                             <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".nav-side-menu">
                                                 <span class="icon-bar">Toggle navigation</span>
                                     <span class="icon-bar"></span>
                                      <span class="icon-bar"></span>
                                       <span class="icon-bar"></span>
                                    </button>
                               </div>
                      </div>
                   </nav>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

      <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    </body>

Your assistance with this matter would be greatly appreciated. Thank you.

Edit: I have successfully managed to hide and show the side menu when resizing the window, as well as displaying the toggle button on smaller screens. However, if the menu is toggled off in a small screen and the window is resized, how can I make the menu reappear?

Answer №1

If you're utilizing Bootstrap 4, there is a handy built-in class that can handle this for you effortlessly. Check out the Bootstrap Navbar Responsive documentation for more details.
This feature ensures responsiveness across various devices, from mobile phones to desktops and beyond. Take some time to explore its capabilities.

Answer №2

Using customized CSS properties, I successfully implemented a feature to toggle the menu visibility on mobile devices. Refer to the feedback provided in the initial thread for more insights.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

css: border radius with a gentle slant

I am attempting to create a sticky note using HTML and CSS in the following code: .div{ margin:50px; position:relative; } .box { background: #ff1; height: 178px; width: 409px; margin: 25px; /*padding: 20px;*/ position: relative; overflow: hidden; bo ...

The Date Filter is causing a glitch in formatting the date value

I have a variable called dateSubmitted with the value of "dateSubmitted": "07-09-20:11:03:30" Currently, I am utilizing Angular Version 7 Within my HTML code, I am using the date filter to format the date like so: <td> {{element.dateSubmi ...

The content of the external json file needs to be allocated to corresponding html divs with matching names

As I am new to jQuery and JavaScript, I am on the search for a method to incorporate data from an external JSON file into HTML code. The data objects in JSON have the same names as their corresponding HTML divs. This should also occur during the onLoad eve ...

Generating pop-up upon loading with CSS3

I have searched through numerous threads and forums in the hopes of finding a solution, but I haven't been successful. My issue lies with triggering a popup on my website. I followed online tutorials to create a popup window, which I was able to do su ...

Preserving Dimension Ratio with Full Width and Height (Trimming Overflow in CSS)

I'm currently developing a full-screen background slideshow. My query is: How can I ensure that an image fills the entire screen while maintaining its aspect ratio? Although min-height and min-width provide some assistance, they do not maintain the ...

Replace all existing CSS styling with my designated CSS selector

I am developing an application for various content management systems where I am unaware of the surrounding CSS and its selectors, yet I want my app to maintain a consistent appearance. An issue I am facing is when an external selector targets one of my e ...

The HTML checkbox remains unchanged even after the form is submitted

On a button click, I have a form that shows and hides when the close button is clicked. Inside the form, there is an HTML checkbox. When I check the checkbox, then close the form and reopen it by clicking the button again, the checkbox remains checked, whi ...

Ways to conceal text links on mobile devices using Bootstrap 4

Is there a way to hide the text of a link on mobile screens using Bootstrap 4? How can this be achieved? HTML <li> <a href="#"><i class="fa fa-icon"></i> Text Link</a> </li> I want to show only the icon on mobile de ...

Align image with the left side of the container

I am struggling with positioning a NextJS Image component within a Material UI Box component. The image is currently centered width-wise, causing alignment issues with the padding of the navigation bar. How can I adjust the positioning to have the image al ...

How to Align Paypal Button in the Middle of a Table Cell within a Concealed Form Using HTML and

Currently, I am in the process of developing a payment page that enables payments through Paypal using Instant Payment Notification. The initiation of this process involves sending a POST request to Paypal via a submit button along with multiple hidden for ...

A guide to properly closing and unmounting a Bootstrap Modal using React.js Portals

My current project involves creating a modal that will display all the data from a table row when clicked. Although I have successfully implemented the modal to appear, I am facing an issue with closing it after it is displayed. Initially, I believed the ...

The basic spinning hover animation is not functioning properly

Can anyone help me with creating a hover effect on an inner circle that causes two outer rings to rotate? I've been struggling to make it work as expected. When I hover over the inner circle, the outer rings only move to the bottom right corner withou ...

The server is throwing a 403 error when trying to submit an AJAX request

I am currently working on a project similar to jsfiddle and encountering an issue during development. Whenever I attempt to make an ajax request with the JS alert() function in a text box, the server is returning a 403 error. Can anyone provide assistance ...

How can I activate a jQuery function only when it is within the viewport?

I have installed a jQuery Counter on my website, but I am experiencing an issue where the counter starts or finishes before reaching the section where the HTML code is embedded. Any assistance with this problem would be greatly appreciated! <script& ...

Creating Material Icons using Pure JavaScriptWould you like to learn how to generate

I am currently exploring how to generate a Material Icon using pure JavaScript (document.createElement) const iconBox = document.createElement("div"); iconBox.style.width = "28px"; iconBox.style.cursor = "pointer"; iconBox.style.display = "flex"; iconBox.s ...

Mysterious failure of JavaScript regular expression when encountering the term "tennis"

We developed a JavaScript script to detect duplicates or potential duplicates, but it seems to have some issues with certain words like "tennis." The script functions correctly in most cases, but fails when analyzing phrases related to the word "tennis" fo ...

Steps for implementing a click event for a navigation drop-down using an HTML helper class

In my MVC 5 application, I have implemented a navigation dropdown. Here is the code snippet: <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="menu> Report ...

Unable to load variables into site.css in order for Flask app to successfully render home.html

I'm encountering difficulties in getting my site.css file to accept two variables passed in from my app.py using Jinja2 templates, namely {{ variable }}. In app.py, I have defined two variables named empty_fill_line and fill_line, which dynamically up ...

The HTML content is not responsive to varying screen sizes

Currently, I am in the process of developing a Wordpress page using WPBakery Page Builder. To enhance the design, I extracted some HTML/CSS code from an existing page by using SnappySnippet and pasted it into the new page within a "Pure html" block. Howeve ...

Is there a way to automatically divide CSS-emulated table cells into multiple rows?

Utilizing the properties display: table and display: table-cell, I am attempting to evenly distribute some divs within a parent container. However, they all end up on the same row, causing overcrowding when there are too many divs like this: Even though I ...