Collapsible flexible-width sidebar using only CSS via transform animation - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Flex

Description

Collapsible flexible-width sidebar using only CSS via transform animation

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
body {<!--from   www  . jav a2 s. com-->
   margin:0;
}

.container {
   display:flex;
}

.sidebar {
   background:Chartreuse;
   transition:all .2s;
}

.sidebar.collapsed {
   transform:translateX(-100%);
   position:absolute;
}
</style> 
 </head> 
 <body> 
  <div class="container"> 
   <div class="sidebar" id="sidebar"> 
    <div>
      SIDEBAR 
    </div> 
   </div> 
   <div class="content">
     lorem bla bla 
    <button onclick="document.getElementsByClassName('sidebar')[0].classList.toggle('collapsed')">toggle Sidebar</button> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials