Glassmorphism Hover Card Animation With HTML & CSS

Glassmorphism Card

Hey Programmers! In this post, we will make Glassmorphism hover card animation with pure HTML & CSS. We will see how we can create a glass morphism effect easily & how we can add a smooth hover effect to the cards & make it eye catchy.

These can be useful when we create modern-looking websites like modern admin pannel, pricing cards, services cards, etc. We will understand the code step by step & how we can use a glass-morphism hover effect that will provide visual feedback, guiding users and making the experience more dynamic.

Concepts Used To Make

  1. CSS Box Model & Box Shadow
  2. CSS Transition
  3. CSS Overflow
  4. CSS Global Selector *
  5. CSS Transform: translate
  6. JavaScript classList add & remove
  7. JavaScript Scroll Event Listener

Also Read: Animated Wallet card with HTML & CSS

Understanding HTML To Make Glassmorphism Hover Cards

  1. HTML Structure:
   <!DOCTYPE html>
   <html lang="en">
   <head>
       <meta charset="UTF-8">
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <title>Document</title>
   </head>
   <body>
  1. Container and Card:
   <div class="container">
       <div class="card show tilt-logo" data-tilt data-tilt-glare="true" data-tilt-scale="1.1">
           <div class="content show">
  1. Card Content:
               <h1>01</h1>
               <h3>Card One</h3>
               <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nam alias, eum sint sunt reprehenderit ex cum assumenda sed accusantium architecto asperiores</p>
               <a href="#">Read More</a>
           </div>
       </div>
   </div>
  1. Closing Tags:
   </body>
   </html>

Also Read: Gradient Glowing Cards With Hover Effect

Understanding CSS To Make Glassmorphism Hover Cards

  1. Importing Google Fonts:
   @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;1,100;1,200&display=swap');
  1. Global Styles:
   * {
       margin: 0px;
       padding: 0px;
       box-sizing: border-box;
       font-family: 'Poppins', sans-serif;
   }
  1. Body Styling:
   body {
       display: flex;
       justify-content: center;
       align-items: center;
       min-height: 100vh;
       background: #161623;
       overflow-x: hidden;
   }
  1. Background Effects:
   .container:after,
   .container:before{
       animation: orbit 5s linear infinite;
       border-radius: 50%;
       box-shadow: 0 0 1rem 0 rgba(0, 0, 0, 0.2);
       content: '';
       height: 150px;
       position: fixed;
       width: 150px;
   }
   .container:before {
       background: radial-gradient(to bottom left, #ffe897, #f98a05);
       right: 60%;
       top: 150px;
   }
   .container:after {
       animation-delay: 2.5s;
       background: radial-gradient(to top left, #e0e793, #6dd0f1);
       right: 30%;
       top: 350px;
       z-index: -1;
   }
  1. Card Styling:
   .container .card {
       position: relative;
       width: 300px;
       height: 400px;
       margin: 30px;
       box-shadow: 20px 20px 50px rgba(0, 0, 0, 0.5);
       border-radius: 15px;
       background-color: rgba(255, 255, 255, 0.1);
       overflow: hidden;
       display: flex;
       justify-content: center;
       align-items: center;
       border-top: 1px solid rgba(255, 255, 255, 0.5);
       border-left: 1px solid rgba(255, 255, 255, 0.5);
       backdrop-filter: blur(5px);
       transform: translateX(400%);
       transition: transform 0.5s ease;
   }
  1. Content Styling:
   .container .card .content {
       padding: 20px;
       text-align: center;
       transform: translateY(100px);
       opacity: 0;
       transition: 0.5s;
   }
  1. Content Hover Effect:
   .container .card:hover .content {
       transform:translateY(0px);
       opacity: 1;
   }
  1. Content Header and Paragraph:
   .container .card .content h1 {
       position: absolute;
       top: -75px;
       right: 30px;
       font-size: 8em;
       color: rgba(255, 255, 255, 0.05);
       pointer-events: none;
       font-weight: 800;
   }
   .container .card .content h3 {
       font-size: 1.8em;
       color: #fff;
       font-weight: 300;
   }
   .container .card .content p {
       font-size: 1em;
       color: #fff;
       font-weight: 300;
   }
  1. Link Styling:
   .container .card .content a {
       position: relative;
       display: inline-block;
       padding: 8px 20px;
       margin-top: 15px;
       background: #fff;
       color: #000;
       border-radius: 20px;
       text-decoration: none;
       font-weight: 500;
       box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
   }
  1. Card Animation:
    • .card:nth-of-type(even) targets every second card, sliding them in from the left. The .show class resets the transform to slide in from the right or left, depending on the card.
    .card:nth-of-type(even){ transform: translateX(-400%) } .card.show{ transform: translateX(0%); }
  2. Orbit Keyframes:
    • The @keyframes orbit animation rotates the pseudo-elements (::before and ::after) around a center point, creating a circular orbit effect.
    @keyframes orbit { from { transform: rotate(0deg) translateX(100px) rotate(0deg); } to { transform: rotate(360deg) translateX(100px) rotate(-360deg); } }
  3. Scrollbar Styling:
    • Customizes the appearance of the scrollbar for the page, making it very thin and adjusting its colors.
    ::-webkit-scrollbar { width: 1px; } ::-webkit-scrollbar-track { background: #f1f1f1; } ::-webkit-scrollbar-thumb { background: #888; } ::-webkit-scrollbar-thumb:hover { background: #555; }

Understanding JavaScript To Make Glassmorphism Hover Cards

  1. Selecting Cards:
   const cards = document.querySelectorAll(".card");
  1. Scroll Event Listener:
   window.addEventListener("scroll", checkcards);
  1. Check Cards Function:
   function checkcards() {
       const triggerBottom = (window.innerHeight / 5) * 4;

       cards.forEach((box) => {
           const boxTop = box.getBoundingClientRect().top;
           if (boxTop < triggerBottom) {
               box.classList.add("show");
           } else {
               box.classList.remove("show");
           }
       });
   }

Source Code Of Glassmorphism Hover Cards

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="container">
        <div class="card  show tilt-logo" data-tilt data-tilt-glare="true" data-tilt-scale="1.1">
            <div class="content show">
               <h1>01</h1>
               <h3>Card One</h3>
               <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nam alias, eum sint sunt reprehenderit ex cum assumenda sed accusantium architecto asperiores</p>
               <a href="#">Read More</a>
            </div>
        </div>
    </div>
</body>
</html>

CSS:

<style>
    @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;1,100;1,200&display=swap');

* {
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #161623;
    overflow-x: hidden;
}
.container:after,
.container:before{
  animation: orbit 5s linear infinite;
  border-radius: 50%;
  box-shadow: 0 0 1rem 0 rgba(0, 0, 0, 0.2);
  content: '';
  height: 150px;
  position: fixed;
  width: 150px;
}
.container:before {
  background: #ffe897;
  background: -moz-radial-gradient(top right, #ffe897, #f98a05);
  background: radial-gradient(to bottom left, #ffe897, #f98a05);
  background: -webkit-radial-gradient(top right, #ffe897, #f98a05);
  right: 60%;
  top: 150px;
}
.container:after {
  animation-delay: 2.5s;
  background: #e0e793;
  background: -moz-radial-gradient(bottom right, #e0e793, #6dd0f1);
  background: radial-gradient(to top left, #e0e793, #6dd0f1);
  background: -webkit-radial-gradient(bottom right, #e0e793, #6dd0f1);
  right: 30%;
  top: 350px;
  z-index: -1;
}

.container .card {
    position: relative;
    width: 300px;
    height: 400px;
    margin: 30px;
    box-shadow: 20px 20px 50px rgba(0, 0, 0, 0.5);
    border-radius: 15px;
    background-color: rgba(255, 255, 255, 0.1);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
    transform: translateX(400%);
    transition: transform 0.5s ease;
}

.container .card .content {
    padding: 20px;
    text-align: center;
    transform: translateY(100px);
    opacity: 0;
    transition: 0.5s;
}
.container .card:hover .content {
    transform:translateY(0px);
    opacity: 1;
}

.container .card .content h1 {
    position: absolute;
    top: -75px;
    right: 30px;
    font-size: 8em;
    color: rgba(255, 255, 255, 0.05);
    pointer-events: none;
    font-weight: 800;
}

.container .card .content h3 {
    font-size: 1.8em;
    color: #fff;
    font-weight: 300;
}

.container .card .content p {
    font-size: 1em;
    color: #fff;
    font-weight: 300;
}

.container .card .content a {
    position: relative;
    display: inline-block;
    padding: 8px 20px;
    margin-top: 15px;
    background: #fff;
    color: #000;
    border-radius: 20px;
    text-decoration: none;
    font-weight: 500;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.card:nth-of-type(even){
    transform: translateX(-400%)
}

.card.show{
    transform: translateX(0%);
}

@keyframes orbit {
  from {
    transform: rotate(0deg) translateX(100px) rotate(0deg);
  }
  to {
    transform: rotate(360deg) translateX(100px) rotate(-360deg);
  }
}

/* width */
::-webkit-scrollbar {
    width: 1px;
  }
  
  /* Track */
  ::-webkit-scrollbar-track {
    background: #f1f1f1; 
  }
   
  /* Handle */
  ::-webkit-scrollbar-thumb {
    background: #888; 
  }
  
  /* Handle on hover */
  ::-webkit-scrollbar-thumb:hover {
    background: #555; 
  }
</style>

JavaScript:

<script>
    
    const cards = document.querySelectorAll(".card");
    
    window.addEventListener("scroll", checkcards);
    
    function checkcards() {
      const triggerBottom = (window.innerHeight / 5) * 4;
    
      cards.forEach((box) => {
        const boxTop = box.getBoundingClientRect().top;
        if (boxTop < triggerBottom) {
          box.classList.add("show");
        } else {
          box.classList.remove("show");
        }
      });
    }
    
    </script>

Last Updated: June 21, 2024

By JSM Hemant

About Author

Hello, Myself Hemant. I Am Web Developer & Likes To Create Awesome Projects By Using MERN, Java, Python, C++. In This Website You Will Get Cool Projects Made With Above Technologies With Full Source Code. You Can Also Follow This Website On Author Social Media:

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

Recent Posts