Off-canvas
JS Optional
The Off-canvas is a navigation layout that the sidebar can slide in and out of the viewport.
By default, the off-canvas menu is collapsed whenever the window width is. But you can add the off-canvas-sidebar-show
class to the off-canvas
to make the sidebar expanded when the window width is larger than or equal to 960px.
The CSS-only version works by leveraging the CSS pseudo-property :target
which works in conjunction with the location hash; clicking on a link with href
#sidebar
changes the URL and displays the HTML element with the id
sidebar
. To close, you can change the location hash to something like #close
or just #
.
In JavaScript you can open the sidebar by adding the class active
to off-canvas-sidebar
, and removing it to close it.
<div class="off-canvas">
<!-- off-screen toggle button -->
<a class="off-canvas-toggle btn btn-primary btn-action" href="#sidebar-id">
<i class="icon icon-menu"></i>
</a>
<div id="sidebar-id" class="off-canvas-sidebar">
<!-- off-screen sidebar -->
</div>
<a class="off-canvas-overlay" href="#close"></a>
<div class="off-canvas-content">
<!-- off-screen content -->
</div>
</div>