"Create a collapsible side menu with Bootstrap and customize it with

My webpage layout is very basic, featuring a navbar at the top and a navigation menu down the left side of the page.

<div class="container">

    <nav class="navbar navbar-toggleable-md navbar-light bg-faded">
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#top-links" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <a class="navbar-brand mr-auto" href="#">Navbar</a>
        <div class="collapse navbar-collapse" id="top-links" style="width:auto;">
            <div class="navbar-nav">
                <a class="nav-item nav-link" href="#">Help Guide</a>
                <a class="nav-item nav-link" href="#">Company Name</a>
                <a class="nav-item nav-link" href="#">Test User</a>
            </div>
        </div>
    </nav>

    <div class="row">
        <div class="col-2">
            <nav class="nav flex-column">
                <a class="nav-link" href="#">Dashboard</a>
                <a class="nav-link" href="#">Users</a>
                <a class="nav-link" href="#">Tasks</a>
            </nav>
        </div>
        <div class="col">
            Content here...
        </div>
    </div>
</div>

The top navbar collapses correctly on mobile devices. I am now attempting to make the left-hand side navigation menu collapse into the same menu on mobile devices. The collapsed menu should include:

Dashboard
Users
Tasks
------
Help Guide
Company Name
Test User

I could simply duplicate the side links in the navbar and only show them on small devices. However, I was wondering if there is a more efficient way to avoid duplicating the links?

Bootstrap 4 Alpha 6 is being used for this project.

Answer №1

To solve this issue, one could implement a complex javascript script. However, it is much easier and more practical to just acknowledge the duplicate links. This approach will greatly improve maintainability.

Answer №2

To achieve a different layout on smaller screens, you can leverage the BS4 flexbox utility classes to adjust the order of elements dynamically. Instead of using the traditional navbar, consider utilizing a nav element for both menus. This approach eliminates the need for additional CSS styling or redundant links...

http://www.example.com/demo

<div class="container">
    <div class="row">
        <div class="col-md-6 flex-first col-12">
            <a class="navbar-brand" href="#">Navbar</a>
        </div>
        <div class="col-md-6 col-3 d-flex flex-last flex-md-unordered">
            <div class="nav flex-md-row flex-column ml-md-auto" id="top-links">
                <a class="nav-item nav-link pl-0" href="#">Help Guide</a>
                <a class="nav-item nav-link pl-0" href="#">Company Name</a>
                <a class="nav-item nav-link pl-0" href="#">Test User</a>
            </div>
        </div>
        <div class="col-9 flex-md-last">
            Content goes here...
        </div>
        <div class="col-3 flex-first flex-md-unordered">
            <nav class="nav flex-column">
                <a class="nav-item nav-link pl-0" href="#">Dashboard</a>
                <a class="nav-item nav-link pl-0" href="#">Users</a>
                <a class="nav-item nav-link pl-0" href="#">Tasks</a>
            </nav>
        </div>
    </div>
</div>

Live Demo

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

Prevent jQuery UI default styling from being applied

I'm curious about how to prevent jQuery UI from adding any classes when initializing $.tabs(). This is the structure of my HTML: <link href="smoothness/jquery-ui-1.8.20.custom.css" rel="stylesheet" type="text/css" /> ... <link href="estilos ...

Move all navigation buttons to the center of the page in mobile view

I am facing an issue with the display of two bootstrap buttons on my site's right navigation bar - Demo and Login. While they appear fine on desktop screens, they overlap each other on mobile devices. I would like these buttons to dropdown and be ce ...

Ways to Show Flexibility through inline CSS Styles?

For this specific element, I am unable to utilize CSS for styling due to constraints within the Google Maps API map. Therefore, I must resort to using inline styling to achieve my desired layout. My goal is to have an image and text displayed side by side, ...

What could be causing my image to be excessively left-aligned in Firefox compared to Chrome?

Having an issue with my code that is displaying differently in Firefox compared to Chrome. <h2>Introducing <span style="font-weight:bold">Analytics by </span> <div class="fi_logo"><img src="IMAGEURL" /></div> </h2& ...

Tips for employing CSS hover within HTML elements?

Is there a way to achieve the following: <li style="hover:background-color:#006db9;"> I have tried this approach but it doesn't seem to work. Is there an alternative method, or do I need to include the CSS in the head section or an external CS ...

Adjusting the background color of two divs simultaneously

I'm trying to create a link that changes its background color when hovered over, but the issue is there are two child divs inside this parent div. When I move the mouse within the boundaries of the parent div, it's actually on a child div. This m ...

Using jQuery to refresh a div element

I am struggling with updating the "right" div in my jsp page using the script below. Despite being contained in a single file, the update does not seem to work. Any assistance is appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//E ...

Using the Bootstrap 3 class visible-lg will cause the span to be placed on a separate line

Is there a way to prevent the class visible-lg from causing the span element to move to a new line? When using the following HTML code, the content displays on a single line: <p>Device is:<span>Unknown</span></p> However, when ut ...

What is the best way to get rid of a Bootstrap modal?

Currently, I am working on a small application to enhance my knowledge of AJAX and JavaScript. Within this project, I have implemented a method called saveData() which is activated upon clicking a 'save' button. Everything seemed to be functionin ...

Assistance needed for aligning a div to the right using

Check out my website at www.whiterootmedia.com. I am trying to prevent my ads on the right from wrapping and disappearing off the screen when the width is around 800px. I believe I need to create a wrap div container, float my ads div to the right, set a ...

The body width does not extend to 100% when the browser window is less than 400 pixels wide

I'm encountering an issue where the HTML and body width are not 100% when the browser window is less than 400px wide. Strangely, everything works perfectly when the window is wider than 400px. Attempts to fix this include setting the body and html pr ...

What is the best way to vertically center a column of images on mobile devices in a responsive manner?

Currently, I am developing an application that showcases the 9 newest photos with a specific tag. To ensure consistency in image sizes, I have set each photo to be 240px wide and 200px tall. My query now is how can I vertically center these images so they ...

The presence of ng-show dynamically adjusts the minimum height of a div element

I am encountering an issue with a div that has the class of wrapper. Inside this div, there is a parent div with the class of content-wrapper. The wrapper div includes a conditional directive ng-show which toggles between displaying or hiding its content. ...

What are the methods for setting the width and height of an Angular mat dialog box?

I'm currently working with a Mat dialog box in Angular and I'm trying to include styles for width and height within that object. However, I'm encountering errors and can't seem to resolve them. Is there another method for setting width ...

Are there any other default light colors in CSS aside from "gray"?

Seeking recommendations for background color combinations. The more suggestions, the better! Thank you :) ...

Opt for buttons for color selection instead of a checkbox toggle

I attempted different approaches to replace the existing checkbox with a button but encountered difficulty. Using the onClick method also proved unsuccessful. VIEW DEMO HERE: https://jsfiddle.net/yxez4a2u/ HTML: <div class="form-check form-switch ...

Ways to adjust the positioning of an image

Seeking assistance, I am currently working on building a portfolio using HTML while following a tutorial. I utilized undraw to insert an image but unfortunately, the image is fixed to the right-hand side: I would like to position the image below my icons, ...

Display a bootstrap toast using a JavaScript class method

One way to display a bootstrap toast is by using the following code snippet: let my_toast = new myToast('title', 'hello world'); my_toast.show(); Currently, I am loading the HTML content from an external file named myToast.html: < ...

Is there a way to modify a CSS class in Chrome that is only visible when I perform a drag action?

For the website project I am working on, I have an element that only changes its style when I drag something over it. This is achieved by adding a CSS class to it. However, editing this style has proven to be challenging because I cannot live edit it in C ...

Dynamic CSS gradients behaving unpredictably in Firefox

Greetings everyone, this is my first time reaching out for help here. I have added a nice gradient background to a page that uses ajax, and it works fine until the content gets lengthy after the call. When I view the page in IE (version 9), the gradient ...