Thursday, June 13, 2024
HomeCSSHamburger menu sidebar - csshint

Hamburger menu sidebar – csshint


Easy methods to create Hamburger menu sidebar utilizing HTML CSS And JS. Designed by Profesor08 a codepen consumer.

<div class="nav-container" tabindex="0">
  <div class="nav-toggle"></div>

  <nav class="nav-items">
    <a category="nav-item" href="#">House</a>
    <a category="nav-item" href="#">About US</a>
    <a category="nav-item" href="#">Product</a>
    <a category="nav-item" href="#">Contact US</a>
  </nav>
</div>
$toggleSize: 40px;
$toggleMargin: 10px;
$toggleLine: 4px;
$toggleColor: pink;

.nav-container {
  place: relative;
  show: inline-block;
  max-width: $toggleSize + $toggleMargin;
  max-height: $toggleSize + $toggleMargin;
  overflow: seen;
  define: none;
  
  //&:focus-within, &:focus {
  &.is-active {
    .nav-toggle {
      &:earlier than, &:after {
        box-shadow: none;
      }
      
      &:earlier than {
        rework: rotate(-45deg);
      }
      
      &:after {
        rework: rotate(45deg);
      }
    }
    
    .nav-items {
      rework: translate(0, 0);
    }
  }
  
  .nav-toggle {
    $offset: $toggleSize * 0.5;
    
    place: relative;
    width: $toggleSize;
    top: $toggleSize;
    margin: $toggleMargin;
    z-index: 2;
    
    &:hover {
      cursor: pointer;
    }
      
    &:earlier than, &:after {
      content material: "";
      place: absolute;
      high: #{$offset - $toggleLine / 2};
      left: 0;
      rework: translate(0, 0);
      width: 100%;
      top: $toggleLine;
      background: $toggleColor;
      transition: rework .3s ease, box-shadow .3s ease;
    }
    
    &:earlier than {
      box-shadow: 0 #{$offset / 1.5} 0 0 $toggleColor;
    }
    
    &:after {
      box-shadow: 0 #{-$offset / 1.5} 0 0 $toggleColor;
    }
  }
  
  .nav-items {
    place: absolute;
    high: 0;
    left: 0;
    min-width: 300px;
    max-width: 50vw;
    width: 100vw;
    top: 100vh;
    z-index: 1;
    padding: 80px 20px 20px 10px;
    transition: rework .3s ease;
    rework: translate(calc(-100% - 50px), 0);
    background: #EFEFEF;
    show: grid;
    grid-template-columns: 1fr;
    grid-gap: 5px 0;
    align-content: begin;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
    
    .nav-item {
      background: darken(#EFEFEF, 5%);
      padding: 10px;
      transition: background-color .3s ease;
      
      &:hover {
        cursor: pointer;
        background: darken(#EFEFEF, 10%);
      }
    }
  }
}

const nav = doc.querySelector(".nav-container");

if (nav) {
  const toggle = nav.querySelector(".nav-toggle");
  
  if (toggle) {
    toggle.addEventListener("click on", () => {
      if (nav.classList.comprises("is-active")) {
        nav.classList.take away("is-active");
      }
      else {
        nav.classList.add("is-active");
      }
    });
    
    nav.addEventListener("blur", () => {
      nav.classList.take away("is-active");
    });
  }
}

 

Hamburger menu sidebar

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments