Select Page
slide-in menu using HTML, CSS, jQuery

In the following post, I will show you how I displayed a slide-in menu in one of my front-end UI development projects.


DEMO

Open demo in a full window – https://demos.webdevpuneet.com/slideinmenu/index.html


HTML


<html>
  <head>
    <title>Switch button using CSS Only</title>
    <meta name="description" content="In the following blog post, I will show you how I displayed a slide-in menu in one of my front-end UI development projects." />
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <h1 style="margin-bottom:50px;">Slide-in menu using HTML, CSS, jQuery</h1>

    <a id="siteHeader__cart" class="siteHeader__cart" title="Cart" href="javascript:;">Click to slide in menu item from right</a>

    <div class="cartMenu">
      <div class="cartMenu__header">
        <h2>Cart Items</h2> <span class="cartMenu__count">(3)</span>
        <a class="cartMenu__close" href="javascript:;">×</a>
      </div>
      <div class="cartMenu__body">
        <div class="cartMenu__item">
          <div class="cartMenu__itemName">
            First Item (25)
          </div>
          <div class="cartMenu__itemDesc">
            <span>1</span> X <span>$390.00</span>
          </div>
          <a class="cartMenu__delete" href="javascript:;">×</a>
        </div>
        <div class="cartMenu__item">
          <div class="cartMenu__itemName">
            Second Item (25)
          </div>
          <div class="cartMenu__itemDesc">
            <span>1</span> X <span class="cartMenu__itemNonDiscountedRate">$605.00</span> <span class="cartMenu__itemDiscountedRate">$555</span>
          </div>
          <a class="cartMenu__delete" href="javascript:;">×</a>
        </div>
        <div class="cartMenu__item">
          <div class="cartMenu__itemName">
            Third Item (10)
          </div>
          <div class="cartMenu__itemDesc">
            <span>1</span> X <span>$490.00</span>
          </div>
          <a class="cartMenu__delete" href="javascript:;">×</a>
        </div>
      </div>
      <div class="cartMenu__footer">
        <div class="cartMenu__total clearfix">
          <span class="cartMenu__totalLabel">TOTAL:</span> <span>$2079</span>
        </div>
        <div class="cartMenu__view">
          <a class="cartMenu__viewLink" href="">VIEW CART</a>
        </div>
        <div class="cartMenu__checkout">
          <a class="cartMenu__btn" href="">CHECKOUT</a>
        </div>
      </div>
    </div>

    <script src="jquery-3.4.1.min.js"></script>
    <script src="scripts.js"></script>

    <div style="margin-top:75px;margin-bottom:30px;">
      <div><a href="https://webdevpuneet.com/wp-content/uploads/2020/04/switch-button.zip">Download files</a>
      <div><a href="https://webdevpuneet.com/switch-button-css-only/">View source code and related information</a></div>
    </div>

  </body>
</html>

CSS

/* Cart Menu */
body {
  overflow-x: hidden;
  overflow-y: auto; }

a{
  text-decoration: none;
}

.cartMenu {
  width: 324px;
  background: #4a4a4a;
  color: #ffffff;
  font-size: 16px;
  position: fixed;
  z-index: 111;
  right: 0;
  top: 0;
  -webkit-transition: 0.5s ease-in-out;
  transition: 0.5s ease-in-out;
  -webkit-transform: translateX(105%);
          transform: translateX(105%);
  -webkit-box-shadow: 0 0 10px #4a4a4a;
          box-shadow: 0 0 10px #4a4a4a;
  border: 1px solid #787878; }

.cartMenu__header {
  padding: 15px 20px;
  position: relative;
  border-bottom: 1px solid #787878;
  line-height: 1; }
  .cartMenu__header h2 {
    font-size: 18px;
    margin: 0;
    display: inline;
    font-family: arial; }
  .cartMenu__header .cartMenu__count {
    font-family: arial, sans-serif;
    font-size: 18px; }
  .cartMenu__header .cartMenu__close {
    position: absolute;
    font-size: 36px;
    color: #ffffff;
    line-height: 0;
    right: 10px;
    top: 10px;
    width: 30px;
    height: 30px;
    padding-top: 15px;
    text-align: center; }
    .cartMenu__header .cartMenu__close:hover {
      text-decoration: none; }

.cartMenu__body {
  min-height: 250px;
  max-height: 350px;
  overflow-y: auto;
  /* width */
  /* Track */
  /* Handle */
  /* Handle on hover */ }
  .cartMenu__body::-webkit-scrollbar {
    width: 10px; }
  .cartMenu__body::-webkit-scrollbar-track {
    background: #f1f1f1; }
  .cartMenu__body::-webkit-scrollbar-thumb {
    background: #888; }
  .cartMenu__body::-webkit-scrollbar-thumb:hover {
    background: #555; }
  .cartMenu__body .cartMenu__item {
    position: relative; }
  .cartMenu__body .cartMenu__itemName {
    font-size: 16px;
    font-weight: bold; }
  .cartMenu__body .cartMenu__itemDesc {
    font-size: 12px; }
  .cartMenu__body .cartMenu__delete {
    color: #e4d39c;
    font-size: 30px;
    line-height: 0;
    position: absolute;
    right: 15px;
    top: 20px; }
    .cartMenu__body .cartMenu__delete:hover {
      text-decoration: none; }
  .cartMenu__body .cartMenu__itemNonDiscountedRate {
    text-decoration: line-through; }
  .cartMenu__body .cartMenu__itemDiscountedRate {
    color: #ff6969; }

.cartMenu__item {
  padding: 10px 20px 15px;
  border-bottom: 1px solid #787878; }

.cartMenu__total {
  padding: 15px 30px;
  height: 50px;
  color: #ffffff;
  background: #505050;
  font-weight: bold;
  text-align: center;
  position: relative; }
  .cartMenu__total .cartMenu__totalLabel {
    position: absolute;
    left: 20px;
    top: 15px; }

.cartMenu__viewLink {
  background: #545452;
  font-weight: bold;
  font-size: 16px;
  line-height: 1;
  display: block;
  height: 50px;
  color: #ffffff;
  text-align: center;
  padding-top: 18px; }
  .cartMenu__viewLink:hover {
    text-decoration: none;
    color: #ffffff; }

.cartMenu__btn {
  background: #e4d39c;
  font-weight: bold;
  font-size: 16px;
  line-height: 1;
  display: block;
  height: 55px;
  color: #4a4a4a;
  text-align: center;
  padding-top: 20px; }
  .cartMenu__btn:hover {
    text-decoration: none;
    color: #4a4a4a; }

.cartMenu--active .cartMenu {
  -webkit-transform: translateX(0%);
          transform: translateX(0%); }

jQuery

$('document').ready(function(){

  // Trigger cart menu slide-in-out action
  $('#siteHeader__cart, .cartMenu__close').click(function(){
    $('body').toggleClass('cartMenu--active');
  });
});

Download files