Search code examples
javascripthtmlcssgoogle-web-designer

How can i minimize the side bar in my website while opening another page?


I am working on a portal, currently designing the UI. I am using frameset here. I need to minimise the left frame (ie Sidebar/Menu) when I click on any link in the sidebar and the web page loads up in the right(Right) frame. The minimised version of the sidebar only display the icons of the tabs and I want an arrow key which will again maximize the sidebar if clicked. a

Here is the code for my frame.html

<!DOCTYPE html>
<html>
  <frameset cols="15%,*" scrolling="yes">
  <frame name = "left" src="menu.html" scrolling="yes">
  <frame name = "center">
</frameset>
</html>

my code for sidebar/menu is menu.html

<!DOCTYPE html>
<html>
<head>

<!--Link to the CSS style sheet-->
<link rel="stylesheet" href="css/menu.css">
<script src="https://kit.fontawesome.com/5c399403c6.js"></script>
</head>

<body>
<!--Sidebar/Menu-->
<div class="wrapper">
  <div class="menu">
    <!--Logo comes here-->
    <h2>Alfred</h2>

    <!--Search Bar-->
    <div class="search">



    <!--Links in the sidebar/menu-->
   <ul>
     <li><input class="search-text" type="text" placeholder="Search here" name="">
     <a class="search-button" href="#">
       <i class="fas fa-search"></i>
     </li>
    <li><i class="fas fa-chart-line"></i><a href="dashboard.html" target ="center" >Dashboard</a></li>
    <li><i class="fas fa-building"></i><a href="hq.html"target ="center" >HQ</a></li>
    <li><i class="fas fa-file-invoice-dollar"></i><a href="accounts.html"target ="center">Accounts</a></li>
    <li><i class="fas fa-users"></i><a href="people.html"target ="center">People</a></li>
    <li><i class="fas fa-at"></i><a href="mail.html"target ="center">Mail</a></li>
    <li><i class="fas fa-handshake"></i><a href="crm.html"target ="center">CRM</a></li>
    <li><i class="fas fa-calendar-alt"></i><a href="calendar.html"target ="center">Calendar</li>
    <li><i class="fas fa-clipboard-list"></i><a href="board.html"target ="center">Board</a></li>
    <li><i class="fas fa-archive"></i><a href="files.html"target ="center">Files</a></li>
    <li><i class="fas fa-headset"></i><a href="desk.html"target ="center">Support Desk</a></li>
    <li><i class="fas fa-cogs"></i><a href="settings.html"target ="center">Settings</li>
  </ul>
  </div>
  </div>
</body>
</html>

and my stylesheet is menu.css

@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
@import url('https://fonts.googleapis.com/css?family=Raleway&display=swap');

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  list-style: none;
  text-decoration: none;
  font-family: 'Muli', sans-serif;
}

i{
  margin: 10px;

}

body{
  background: #391E57;
}

.wrapper{
  display: flex;
  position: relative;
  color: #ECE4F4;

}

.wrapper .menu {
  position: fixed;
  width: 200px;
  height: 100%;
  background: #391E57;
  padding: 30px 0;

}

.wrapper .menu h2{
  color: #fff;
  text-align: center;
  margin-bottom: 30px;
  font-family: 'Raleway', sans-serif;
  letter-spacing: 4.5px;
  transition: all .2s ease-in-out;
}

.wrapper .menu h2:hover{
  color: #53D2F5;
  transform: scale(1.1);
}

.search-text{
  width: 140px;
  height: 25px;

}


.wrapper .menu ul li{
  padding: 5px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  border-top: 1px solid rgba(225, 225, 225, 0.05);
}

.wrapper .menu ul li a{
  color: #9F9CA2;
  display: inline;

}

.wrapper .menu ul li .fas{
  width: 25px;
  color: #9F9CA2;
  transition: all .2s ease-in-out;

}

.wrapper .menu ul li:hover .fas{
  color: #53D2F5;
   transform: scale(1.1);
}


.wrapper .menu ul li:hover{
  background: #79668F;
}

.wrapper .menu ul li:hover a{
  color: #fff;
}

Solution

  • There are a couple ways you could partially hide a sidemenu component, and it depends on how you structure the rest of your page. You could use margin, width, absolute positioning... One thing you will have to do for sure is toggle create a class for when the sidemenu is supposed to be full width, and when it is supposed to be partially open.

    So lets say you choose to use width:

    1. Create a .hide class for your .wrapper .menu with the width you want when it is partially closed, like that:

      .wrapper .menu.hide { width: 50px; }

    2. Add the ID sidemenu to your component to be able to reference it better. Then, create a javascript function to toggle the sidemenu state (recommend using Jquery):

      toggleSidemenu = () => { $("#sidemenu").toggleClass("hide"); }

    You can also create functions to always close or always open it, using $("#sidemenu").removeClass("hide"); and $("#sidemenu").addClass("hide");, they may come in handy.

    1. Call the toggleSidemenu function wherever you want to toggle it, like in a header button or whenever you change pages.

    I also recommend adding a transition so that the transition between states is smooth, it looks a lot better. ;)

    #sidemenu {
      position: fixed;
      width: 200px;
      height: 100%;
      background: #391E57;
      padding: 30px 0;
      -webkit-transition: width 2s
      transition: width 2s;
    }