Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: Keeping content responsive when using an offcanvas sidebar

Here is the current working example of what I have going on:

Fiddle.

This is what I would like to do:

The content (i.e. the three circles, or anything inside the <section>) is responsive and resizes itself to fit the current browser size. Try making the Fiddle render window small and notice how the circles stack.

Now, when I click the hamburger menu, I want the same thing to happen. The sidebar that appears is using an "offcanvas reveal" to push itself into view, but is not triggering responsive behavior; it simply shoves all content right off the edge of the page. How can I remedy this?

Here is 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 here -->
        </div>
    </div>
</div>
like image 427
daveycroqet Avatar asked Sep 25 '15 03:09

daveycroqet


People also ask

Which is the right placement of an Offcanvas?

There's no default placement for offcanvas components, so you must add one of the modifier classes below; .offcanvas-start places offcanvas on the left of the viewport (shown above) .offcanvas-end places offcanvas on the right of the viewport. .offcanvas-top places offcanvas on the top of the viewport.

What is Offcanvas menu?

An off-canvas menu, also called a flyout or side panel, is a section of your website that appears from the side of the screen when it is triggered by an action on the page. Typically, the trigger is the click of a button. However, it can also be activated by an icon, image or text.


2 Answers

From the question it is not clear what you are looking for. I have created a possible solution for your issue

http://jsfiddle.net/5vqu5082/

.canvas-slid.canvas{
    width: 30%;
}
like image 191
Rejoy Avatar answered Sep 28 '22 00:09

Rejoy


working demo of an off canvas menu as i described in my comments: http://jsfiddle.net/b6nopc8e/

HTML:

<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>

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);
}

.boring #site-menu {
    transform: translateX(0);   
    transform: translate3d(0, 0, 0);
    -webkit-transform: translateX(0);   
    -webkit-transform: translate3d(0, 0, 0);    
    -ms-transform: translateX(0);   
    -ms-transform: translate3d(0, 0, 0);    
}
.boring .show-nav #site-menu {
    transition: 900ms ease all;      
    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);   
}

.boring .show-nav #site-canvas {
    transform: translateX(0);   
    transform: translate3d(0, 0, 0);
    -webkit-transform: translateX(0);   
    -webkit-transform: translate3d(0, 0, 0);
    -ms-transform: translateX(0);   
    -ms-transform: translate3d(0, 0, 0);
}

/********************************
/* WIREFRAME ELEMENTS
/*******************************/
#site-wrapper {
    box-sizing: border-box;
    height: 100%;
    width: 100%;
}

#menuToggle {
    margin-right: 10px;
    position: fixed;
        top: 0; right: 0;
    z-index: 888;
}

#site-menu {
    background-color: #999;
    height: 100%;
    position: fixed;
    top: 0; right: -330px;
    width: 300px;   
    z-index: 777;   
}

#site-menu:after { z-index: 999; }

#site-canvas {
    backface-visibility: hidden;
    height: 100%;   
    transform: translateX(0);   
    transform: translate3d(0, 0, 0);    
    width: 100%;
}

JQUERY

/********************************
/* 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);

/********************************
/* OFF CANVAS MENU HEIGHT
/*******************************/
(function($){
  jQuery(document).ready(function(){
            $('#site-canvas').css({'min-height':($(window).height())+'px'});
            $(window).resize(function(){
                $('#site-canvas').css({'min-height':($(window).height())+'px'});
            });
    });
})(jQuery);

Some notes: This menu is on the right. but by changing the translate numbers you can move it to the right. This is a really quick rough strip down so the code may be a bit messy.

like image 41
Destination Designs Avatar answered Sep 28 '22 00:09

Destination Designs