Skip to main content

Simple Responsive Sidebar

Create a very simple responsive sidebar in HTML, CSS and one tiny line of JavaScript.

DEMO

🦁 LION
🦄 UNICORN
🤗 CONTENT AREA

HTML

<div id="AreaBody">
  <!-- (A) SIDEBAR -->
  <div id="AreaSide">
    <!-- (A1) EXPAND/COLLAPSE SIDEBAR -->
    <button id="btnToggle" onclick="document.getElementById('AreaBody').classList.toggle('open')">
      &#9776;
    </button>
 
    <!-- (A2) SIDEBAR ITEMS -->
    <div class="item">
      <span class="ico">&#129409;</span> 
      <span class="txt">LION</span>
    </div>
    <div class="item">
      <span class="ico">&#129412;</span> 
      <span class="txt">UNICORN</span>
    </div>
  </div>
 
  <!-- (B) MAIN CONTENTS -->
  <div id="AreaContent">&#129303; CONTENT AREA</div>
</div>

CSS

/* (A) BIG SCREEN */
/* (A1) 2 COLUMN LAYOUT */
#AreaBody { display: flex; }
#AreaSide, #AreaContent { padding: 10px; }
#AreaSide {
  width: 200px;
  background: Gold;
}
#AreaSide * { margin-bottom: 10px; }
#AreaContent {
  width: 100%;
  background: PowderBlue;
}
/* (A2) HIDE DRAWER BUTTON */
#btnToggle { display: none; }
 
/* (B) SMALL SCREEN */
@media screen AND (max-width:768px) {
  /* (B1) SHOW TOGGLE SIDEBAR BUTTON */
  #btnToggle {
    display: inline-block;
    width: 100%;
    font-size: 24px;
  }

  /* (B2) COLLAPSED SIDEBAR BY DEFAULT */
  #AreaSide { 
    width: 50px; 
    text-align: center;
    transition: all 0.2s;
  }
  #AreaSide .ico { font-size: 30px; }
  #AreaSide .txt { display: none; }

  /* (B3) EXPAND SIDEBAR */
  #AreaBody.open #AreaSide {
    width: 200px;
    text-align: left;
  }
  #AreaBody.open .ico { font-size: inherit; }
  #AreaBody.open .txt { display: inline; }
}

Comments

Popular posts from this blog

Create Vertical Text - CSS

From the old internet, the direction of text is pretty much fixed on left-to-right. In modern CSS has addressed the issue and supports vertical text with ease. Right to Left Vertical Text Right to Left Vertical Text HTML <div class= "v-rl" > <p> Right to Left </p> <p> Vertical Text </p> </div> CSS .v-rl { writing - mode : vertical - rl; } Left to Right Vertical Text Left to Right Vertical Text HTML <div class= "v-lr" > <p> Left to Right </p> <p> Vertical Text </p> </div> CSS .v-lr { writing - mode : vertical - lr; } All Characters Upright All Characters Upright Ultraman ウルトラマン HTML <div class= "t-upright" > <p> All Characters </p> <p> Upright </p> <p> Ultraman ウルトラマン </p> </div> CSS .t-upright { writing - mode : vertical - rl; text - orie...

Distortion Glitch Text Effect - CSS

  Use multiple text-shadow properly in CSS on a text by comma separating the values. DEMO Distortion CSS h2 { color : darkorange ; font-family : sans-serif ; font-size : 3.5em ; text-transform : uppercase ; text-shadow : -3px -3px 0 cyan , 3px 3px 0 pink ; }

Input Range with CSS

  Use ::in-range and ::out-of-range pseudo-classes to style input depending on input value. DEMO 1 to 10 are valid. HTML < label > 1 to 10 are valid .</ label > < input type = "number" value = "1" min = "1" max = "10" > CSS input : in - range { background - color: limegreen; } input :out - of - range { background - color: orange; }