Vue collapsible left nav with flex
by Joe Saad
HTML
<div id="app">
<div id="wrapper" class="wrapper">
<div id="aside" :class="'sidebar ' + [isClosed ? 'isClosed' : '']">
<ul :class="'nav ' + [isClosed ? 'isClosed':'']">
<li><a href="#">Home</a></li>
<li><a href="#">Experience</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Bio</a></li>
<li><a href="#">Contact</a></li>
</ul>
<!-- <div>
some extra text
</div> -->
</div>
<!-- /Aside -->
<div id="content" class="content">
<a class='button' @click="isClosed = !isClosed"></a>
<h1>Flexbox Off-Canvas Side Menu</h1>
<h2>Easy to use</h2>
</div>
<!-- /Content -->
</div>
SCSS
$verylight: #f6f7f8;
$smallspace: 20px;
$mediumspace: 30px;
$largespace: 40px;
$defaultspace: $smallspace;
/*
* ==== RESETS ====
*/
* {
margin: 0;
padding: 0;
}
*,
*:before,
*:after {
box-sizing: border-box;
}
/*
* ==== IMPORTS ====
*/
// @import "scss/_vars.scss";
/*
* ==== STYLING ====
*/
html,
body {
height: 100%;
}
body {
font-family: -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
}
.wrapper {
display: flex;
height: 100%;
padding: $defaultspace;
}
/*
* ==== SIDEBAR ====
*/
.sidebar {
display: flex;
min-height: 100%;
flex-grow: 1;
transition: all .3s;
border: 1px solid red;
&.isClosed {
// TBD
// display: none;
flex-grow: 0;
min-width: 15px;
}
& ul.nav {
display: flex;
flex-direction: column;
width: 100%;
opacity: 1; // height: 100%;
// align-items: center; /* horizontally aligns */
// justify-content: flex-end; /* vertically aligns all <ul.nav> children */
&.isClosed {
display: none;
}
}
& ul.nav li {
list-style: none;
padding: $smallspace 0;
}
& ul.nav li a {
text-decoration: none;
}
& ul.nav li:last-child {
// TBD
}
& ul.nav li:last-child a {
// TBD
}
& div {
align-self: flex-end;
}
}
/*
* ==== CONTENT ====
*/
.content {
background-color: $verylight;
min-height: 100%;
flex-grow: 9;
padding: $largespace;
transform: translate3d(0, 0, 0);
transition: transform .3s;
&.isClosed {
// transform: translate3d(220px,0,0);
}
}
/*
* ==== TOGGLE BUTTON ====
*/
a.button {
cursor: pointer;
position: absolute;
top: 10px;
left: 10px;
&:before {
content: '\f0c9';
font: 30px fontawesome;
}
}
/*
* ==== MEDIA QUERIES ====
*/
@media only screen // and (min-device-width : 414px)
and (max-device-width: 736px) and (orientation: portrait) {
.wrapper {
flex-direction: column;
}
.sidebar {
// min-height:...
Vue
new Vue({
el: "#app",
data: {
isClosed: false
}
})