Optimizing Content Responsiveness with Bootstrap in Offcanvas Sidebar Layouts

Here is an example of my current working code:

Fiddle.

This is what I want to achieve:

The content within the <section> (such as the three circles) is designed to be responsive and adjust itself according to the browser size. If you resize the Fiddle render window, you'll see how the circles stack accordingly.

Now, when I click on the hamburger menu, I expect the same responsive behavior. The sidebar that slides in uses an "offcanvas reveal" effect but it doesn't trigger the responsive layout. Instead, all the content gets pushed off the edge of the page. How can I fix this issue?

Below is a snippet of my code:

<div id="wrapper">
    <header>
        <div class="navmenu navmenu-default navmenu-fixed-right">
            <ul class="nav navmenu-nav">
                <li><a href="#">Link 1</a></li>
                <li><a href="#">Link 2</a></li>
                <li class="active"><a href="#">Link 3</a></li>
                <li><a href="#">Link 4</a></li>
            </ul>
        </div>
    </header>
    <div class="canvas">
        <div class="navbar navbar-default navbar-fixed-top">
            <button type="button" class="navbar-toggle" data-toggle="offcanvas" data-recalc="false" data-target=".navmenu" data-canvas=".canvas">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="container">
            <!-- content goes here -->
        </div>
    </div>
</div>

Answer №1

The question does not provide enough information about your specific needs, but I have come up with a potential solution to address your problem

http://jsfiddle.net/72nkfp4g/

.canvas-slid.canvas{
    width: 25%;
}

Answer №2

Here is a live demonstration of an off-canvas menu based on the description provided in my comments: http://jsfiddle.net/b6nopc8e/

Below is the HTML code:

<div id="site-wrapper" class="container-fluid">
    <div id="menuToggle">
        <btn id="menuButton" class="main-menu btn btn-transparent pull-right" data-transition="boring">
        <i class="fa fa-ellipsis-v fa-3x"></i><br />
        <div>menu</div><div style="display:none;">close</div></btn>
    </div>
    <nav id="site-menu">
        <ul class="nav">
            <li><a href="/">Link</a></li>
            <li><a href="/">Link</a></li>
            <li><a href="/">Link</a></li>
        </ul>
    </nav>  
    <div id="site-canvas">
        <div id="mainbody" class="container-fluid">
            <div class="col-md-12">
                <h1>Hello World</h1>
            </div>
        </div>
    </div>
</div>

Next, we have the CSS:

#menuButton {
    width: 45px;
    height: 45px;
}

/********************************
/* OFF CANVAS MENU 
/*******************************/
.show-nav #site-canvas {
    transform: translateX(-330px);      
    transform: translate3d(-330px, 0, 0);
    -webkit-transform: translateX(-330px);      
    -webkit-transform: translate3d(-330px, 0, 0);
    -ms-transform: translateX(-330px);      
    -ms-transform: translate3d(-330px, 0, 0);
}

...

Lastly, the jQuery code:

/********************************
/* OFF CANVAS MENU
/*******************************/
(function($){
  jQuery(document).ready(function(){
        var special = ['reveal', 'top', 'boring', 'perspective', 'extra-pop'];
            // Toggle Nav on Click
            $('.main-menu').click(function() {
                var transitionClass = jQuery(this).data('transition');
                if ($.inArray(transitionClass, special) > -1) {
                    $('body').removeClass();
                    $('body').addClass(transitionClass);
                } else {
                    $('body').removeClass();
                    $('#site-canvas').removeClass();
                    $('#site-canvas').addClass(transitionClass);
                }
                $('#site-wrapper').toggleClass('show-nav'); 
                $('.main-menu i').toggleClass('fa-ellipsis-v fa-ellipsis-h');
                $(".main-menu div").html("menu");
                $('.main-menu div').toggle();
                return false;
            }); 
    });
})(jQuery);

...

A quick note: The off-canvas menu is positioned to the right by default, but you can adjust the translate values to move it as needed. This code snippet is a simplified version, so please excuse any messiness.

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

The width of the <ul> element does not properly accommodate the width of the <li> elements during the animation that updates the width of the <li>

I am currently working on implementing a typing animation in React. The li element has an animation that recursively changes its width from 0px to 100%. However, I have noticed that when the width of the li changes, the parent ul does not adjust its width ...

Avoid placing the label within a form-inline in Bootstrap to maintain proper formatting and alignment

I am working on a form where I have two fields inline within a form-inline div. I am looking to move the labels of these fields above them rather than next to them. How can I achieve this without affecting the layout of the fields? Here is a CodePen link ...

Modifying HTML tag attributes with inline server scripts

I am working with a submit button and trying to change the background color of the button itself after it has been clicked using inline server tags. <form id="form1" runat="server"> <input type="submit" id="submit" value="Submit" runat="server"/& ...

When the URL is modified, triggering an event to load

Is there a way to make a page load directly to a specific section and automatically open an accordion? For instance, I have a page with multiple accordions displayed vertically. I already know that using id's in the URL like page#accordion1 will scro ...

The jsonData fails to display on the console without any errors, it simply refuses to print

.controller('StocksCtrl',['$scope','$stateParams','$http', function($scope, $stateParams) { //Retrieving stock data from Yahoo Finance API $http.get("http://finance.yahoo.com/webservice/v1/symbols/YHOO/quo ...

Using jQuery and CSS to Filter and Sort Content

I need help with filtering a list of content based on their class names. The goal is to show specific items when a user clicks on one of two menus. Some items have multiple classes and users should be able to filter by both menus simultaneously. Currently ...

Exploring the versatility of using multiple string arrays in TypeScript

I'm facing a simple problem that I just can't seem to solve. My goal is to extract data from a service and store it in an array, but no matter what I try, I can't get the desired outcome using properties or arrays. For example: abc~sdfgsdg| ...

Assign the textbox's value to be the earliest selected date from the datepicker

Can anyone assist me? I have a working code that activates only the specific day of the week I want on the datepicker. However, the textbox doesn't have a default value and I would like it to display the first date activated in the datepicker. In th ...

Trigger a click (or selection) on a specific dropdown option using jQuery

I am attempting to initiate a click function upon page load using jQuery on a dropdown option within Chosen, in order to activate a subsequent action. Unfortunately, I have not been successful in getting it to work. I have tried the following methods: jQ ...

Leveraging the power of ReactJS alongside Google Tag Manager

Looking for a way to track my application using Google Tag Manager, I stumbled upon a popular package at https://www.npmjs.com/package/react-google-tag-manager. However, despite following the instructions, I am having trouble configuring it properly! Foll ...

Centered Fixed Upward Scrolling Div

Currently facing a challenge with my project involving a chat interface created in Angular. I am struggling with the CSS styling as the chat starts at the top and scrolls downward off-screen as the conversation progresses. Although I can scroll along with ...

AngularJS does not recognize Model as a date object in the input

I am attempting to utilize AngularJS to showcase a date using an input tag with the type attribute set to date: <input ng-model="campaign.date_start" type="date"> Unfortunately, this approach is resulting in the following error message: Error: err ...

Exploring the power of VueJs through chaining actions and promises

Within my component, I have two actions set to trigger upon mounting. These actions individually fetch data from the backend and require calling mutations. The issue arises when the second mutation is dependent on the result of the first call. It's cr ...

Invoke the function when the user inputs text into the textbox

<textarea name="" id="" #text cols="30" (keydown)="WordCounter()" (change)="WordCounter()" rows="8" [(ngModel)]="user_text" placeholder="Type something here"></textare ...

Simulating jQuery/JS simulation has never been more exciting

Although I am still relatively new to jQuery and Javascript, I have a question about implementing tab functionality. I have created 4 clickable tabs using two functions - one that executes on click, and another that simulates the click every 5 seconds to c ...

Is it possible for the $_REQUEST and $_GET variables to signal an undefined index even though they

Trying to retrieve the $_REQUEST value and store it in a variable. $id = $_REQUEST['ID']; I have also tried using isset, but still no value is returned. However, when I use: print_r($_REQUEST); I can see the desired value. Here is the code: ...

Enhance your search experience with AJAX-powered search boxes

I need to implement multiple textboxes on my webpage, each with its own search query to retrieve data from the database. While I have successfully implemented this for one textbox, I am facing difficulties getting it to work for two or more textboxes. He ...

What strategies are most effective in managing unexpected drag and drop events while working on a project?

Can you forgive my quirky question? I'm facing a problem with drag/drop events while working on an Electron project. The issue goes like this: During development (using Vue / Electron-builder, etc.), I run in "electron-builder:serve" mode. This mode ...

setting a callback function as a variable

I have encountered an issue where I am passing a callback function but unable to call it when the onreadystatechange changes its value, specifically request.onreadystatechange = func. Even though I receive a response from the server when making the ajax ...

Utilizing children or CSS attributes in customizing component styles within Chakra UI's configuration settings

Can children props or CSS attributes such as title be passed to the component style configuration in Chakra UI? https://i.sstatic.net/3ksWF.png https://i.sstatic.net/wBeoH.png ...