How do I create a BS4 sidebar menu that toggles on click and replaces an icon? See the code below:
.toggle {
display: none;
}
.menu-head label {
color: black;
cursor: pointer;
}
.container {
overflow: hidden;
display: inline-block;
}
.side-bar {
background:#3e4140;
position: absolute;
height: 100%;
width: 200px;
color:#fff;
transition: margin-left 0.5s;
}
.side-bar ul {
list-style: none;
padding: 0px;
}
.side-bar ul li.menu-head {
padding: 20px;
background-color: #ECECEA;
}
.side-bar ul .menu li a {
color:#fff;
text-decoration: none;
display: inline-table;
width: 100%;
padding-left: 20px;
padding-right: 20px;
padding-top: 10px;
padding-bottom: 10px;
}
.side-bar ul .menu li a:hover {
border-left:3px solid #ECECEA;
padding-left:17px;
}
.content {
padding-left: 200px;
transition: padding-left 0.5s;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home Page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="wrapper">
<div class="side-bar">
<ul>
<li class="menu-head">
<div class="row">
<div class="col-9">
<img class="img-responsive" height="60px" width="60px" src="https://www.w3schools.com/w3css/img_avatar3.png" alt="Logo">
</div>
<div class="col-3">
<button class="btn btn-sm btn-dark"><i class="fa fa-times" aria-hidden="true"></i></button>
</div>
</div>
</li>
<div class="menu">
<li>
<a href="#">Home <i class="fa fa-home" aria-hidden="true"></i></a>
</li>
<li>
<a href="#">Calendar <i class="fa fa-calendar" aria-hidden="true"></i></a>
</li>
<li>
<a href="#">Education <i class="fa fa-university" aria-hidden="true"></i></a>
</li>
<li>
<a href="#">Settings <i class="fa fa-cog" aria-hidden="true"></i></a>
</li>
</div>
</ul>
</div>
<div class="content">
<div class="card m-5">
<div class="card-header">Featured</div>
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
I am trying to design a button with a Font Awesome icon that closes the menu, but still displays icons on the side when closed. The close (X) icon should change to a menu icon (three horizontal lines). The Font Awesome 4.7 code for the menu icon is
<i class="fa fa-bars" aria-hidden="true"></i>
. The toggle functionality should be achieved using pure CSS without jQuery. Can someone provide a solution for this? Thank you.