Last active
December 19, 2019 18:21
-
-
Save DarranShepherd/61a7eed399088d4dca5426a5be04bb90 to your computer and use it in GitHub Desktop.
Collapsible Sidebar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, | |
body { | |
height: 100%; | |
margin: 0; | |
} | |
#wrapper { | |
display: flex; | |
height: 100%; | |
} | |
section { | |
background-color: #ccc; | |
display: inline-flex; | |
justify-content: stretch; | |
} | |
#content div { | |
transition: .3s ease all; | |
} | |
section.hidden #content div { | |
transform: translate3d(-1px); | |
margin-left: -1px; | |
width: 1px !important; | |
} | |
#divider { | |
background-color: #999; | |
flex-grow: 0; | |
flex-basis: auto; | |
display: flex; | |
align-items: center; | |
} | |
#divider span { | |
margin: 0.25em; | |
} | |
section #divider::after { | |
content: '<'; | |
margin: 0.5em; | |
} | |
section.hidden #divider::after { | |
content: '>' | |
} | |
#wrapper div.content { | |
padding: 1em; | |
background-color: lightcyan; | |
} | |
#rest { | |
flex-grow: 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="wrapper"> | |
<div class="content">Test</div> | |
<section> | |
<div id="content"> | |
<div style="width: 12em;"> | |
<ul class=""> | |
<li>Foo</li> | |
<li>Bar</li> | |
<li>Baz</li> | |
</ul> | |
</div> | |
</div> | |
<a id="divider" onclick="toggle()"></a> | |
</section> | |
<div id="rest" class="content"> | |
<p>Other content</p> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document | |
.addEventListener( | |
'DOMContentLoaded', | |
() => document.querySelector('#divider') | |
.addEventListener('click', toggle))); | |
function toggle() { | |
let ul = document.querySelector('section'); | |
ul.classList.toggle('hidden'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment