A Pen by Serdar Balcı on CodePen.
Created
December 25, 2021 17:39
-
-
Save sbalci/c6a6dddcc5af107b27bd4265bda801e3 to your computer and use it in GitHub Desktop.
Simple Sidebar that pushes content
This file contains hidden or 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="sidebar" class="collapsed"> | |
</div> | |
<div id="content"> | |
<button title="Toggle sidebar"></button> | |
<h3>Some content</p> | |
</div> |
This file contains hidden or 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
const button = document.querySelector('button'); | |
button.addEventListener('click', _ => { | |
document.getElementById('sidebar').classList.toggle('collapsed'); | |
}) |
This file contains hidden or 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 { | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
} | |
#sidebar, #content { | |
height: 100%; | |
overflow:auto; | |
float:left; | |
transition: width .35s; | |
} | |
#sidebar { | |
background:white; | |
width: 30%; | |
box-shadow: 2px 0 4px rgba(0,0,0,0.5); | |
} | |
#sidebar.collapsed { | |
width: 0; | |
} | |
#sidebar.collapsed + #content { | |
width: 100%; | |
} | |
#content { | |
background:gray; | |
width: 70%; | |
} | |
button { | |
width: 30px; | |
height: 30px; | |
border-radius: 50%; | |
border:none; | |
outline:none; | |
background: black; | |
margin: 20px; | |
cursor:pointer; | |
} | |
h3 { | |
font-family: sans-serif; | |
color:white; | |
text-align:center; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment