JSFiddle - React, Tailwind, and code Playground

by Kawaljit Singh

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Navigation Bar</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <script
      src="https://kit.fontawesome.com/6cc49d804e.js"
      crossorigin="anonymous"
    ></script>
    <script src="js/scripts.js"></script>
  </head>

  <body>
    <div id="sidenav">
      <div id="sidenav-brand">
        <div id="sidenav-heading" style="display:none;">
          <h2>Expanded</h2>
        </div>
        <div id="sidenav-expand">
          <i id="expand-icon" class="fas fa-angle-double-right fa-2x"></i>
        </div>
      </div>

      <div id="sidenav-links"></div>
    </div>
  </body>
</html>

CSS

#sidenav {
  height: 100%;
  width: 75px;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: #1e1e2d;
  overflow-x: hidden;
  color: white;
  transition: 0.8s;
}

#sidenav-brand {
  padding: 25px 10px;
  background-color: aqua;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

#sidenav-heading {}

#sidenav-expand {
  text-align: center;
}

.expand {
  transform: rotate(180deg);
}

JavaScript

let sidenav = document.getElementById("sidenav");
  sidenav.onmouseover = function() {
    //expandNav();
    sidenav.style.width = "250px";
    document.getElementById("expand-icon").classList.add("expand");
    document.getElementById("sidenav-expand").style.textAlign = "right";
    document.getElementById("sidenav-heading").style.display = "inline-block";
  };
  sidenav.onmouseout = function() {
    //closeNav();
    sidenav.style.width = "75px";
    document.getElementById("expand-icon").classList.remove("expand");
    document.getElementById("sidenav-expand").style.textAlign = "center";
    document.getElementById("sidenav-heading").style.display = "none";
  };