CSS Split Card Hover Overlay Effect

CSS Split Card Hover Overlay Effect
Code Snippet:Split Card Hover Effect
Author: Simon Goellner
Published: January 16, 2024
Last Updated: January 22, 2024
Downloads: 5,625
License: MIT
Edit Code online: View on CodePen
Read More

This CSS code snippet helps you to create card split overlay effect on hover. Basically, it uses splitting jQuery plugin to create an animated text overlay over the card element with a smooth transition.

You can use this effect on cards, sliding elements or posts grid to show the summary over the images on hover.

How to Create CSS Split Card Hover Overlay Effect

1. First of all, load the Normalize and Google Fonts CSS into the head tag of your HTML document.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700;800&amp;display=swap'>

2. After that, create the HTML structure for the cards as follows:

<main id="main">
  <h1>Card Split Hovers</h1>
  <div class="card"><img src="https://images.unsplash.com/photo-1535498730771-e735b998cd64?ixlib=rb-1.2.1&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=687&amp;q=80" alt="A City skyline at sunset"/>
    <div class="text">
      <h2 data-splitting="">The City</h2>
      <p data-splitting="">Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos excepturi nostrum necessitatibus doloremque? Quasi non molestias odio.  Quasi non molestias odio.</p>
    </div>
  </div>
  <div class="card"><img src="https://images.unsplash.com/photo-1586500036706-41963de24d8b?ixlib=rb-1.2.1&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=687&amp;q=80" alt="A City skyline at sunset"/>
    <div class="text">
      <h2 data-splitting="">The Beach</h2>
      <p data-splitting=""> Quasi non molestias odio. Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos excepturi nostrum necessitatibus doloremque? Quasi non molestias odio.</p>
    </div>
  </div>
</main> 

3. Now, style the cards using the following CSS:

:root {
  --cover-timing: 0.5s;
  --cover-ease: cubic-bezier(0.66, 0.08, 0.19, 0.97);
  --cover-stagger: 0.15s;
  --text-timing: .75s;
  --text-stagger: 0.015s;
  --text-ease: cubic-bezier(0.38, 0.26, 0.05, 1.07);
  --title-stagger: 0.05s;
  --highlight: white;
}

.card {
  position: relative;
  overflow: hidden;
  aspect-ratio: 9/12;
  display: flex;
  flex-direction: column;
  border-radius: 7px;
  box-shadow: rgba(255, 255, 255, 0.3) 0 5vw 6vw -8vw, rgba(255, 255, 255, 0) 0 4.5vw 5vw -6vw, rgba(50, 50, 80, 0.5) 0px 4vw 8vw -2vw, rgba(0, 0, 0, 0.8) 0px 4vw 5vw -3vw;
  transition: box-shadow 1s var(--cover-ease);
}
.card > * {
  z-index: 2;
}
.card > img {
  z-index: 0;
  transition: all 0.8s cubic-bezier(0.66, 0.08, 0.19, 0.97);
}
.card::before, .card::after {
  content: "";
  width: 100%;
  height: 50%;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  position: absolute;
  transform-origin: left;
  transform: scaleX(0);
  transition: all var(--cover-timing) var(--cover-ease);
  z-index: 1;
}
.card::after {
  transition-delay: var(--cover-stagger);
  top: 50%;
}
.card:hover {
  box-shadow: white 0 5vw 6vw -9vw, var(--highlight) 0 5.5vw 5vw -7.5vw, rgba(50, 50, 80, 0.5) 0px 4vw 8vw -2vw, rgba(0, 0, 0, 0.8) 0px 4vw 5vw -3vw;
}
.card:hover::before, .card:hover::after {
  transform: scaleX(1);
}
.card:hover h2 .char, .card:hover p .word {
  opacity: 1;
  transform: translateY(0);
  color: inherit;
}
.card:hover h2 .char {
  transition-delay: calc(0.1s + var(--char-index) * var(--title-stagger));
}
.card:hover p .word {
  transition-delay: calc(0.1s + var(--word-index) * var(--text-stagger));
}
.card:hover img {
  transform: scale(1.1);
}
.card:nth-of-type(1) {
  --highlight: coral;
}
.card:nth-of-type(2) {
  --highlight: #56ffe5;
}

.text {
  position: absolute;
  inset: 20px;
  top: auto;
}

h2 {
  font-size: 30px;
  font-size: clamp(20px, 4vw, 40px);
  font-weight: 800;
  margin-bottom: 0.2em;
}

p {
  font-size: 12px;
  font-size: clamp(10px, 1.25vw, 14px);
  line-height: 1.4;
  text-align: justify;
  margin-top: 0.2em;
  margin-bottom: 0;
}

h2 .char,
p .word {
  color: var(--highlight);
  display: inline-block;
  opacity: 0;
  position: relative;
  transform: translateY(20px);
  transition-property: transform, opacity, color;
  transition-timing-function: var(--text-ease);
  transition-duration: var(--text-timing), var(--text-timing), calc(var(--text-timing)*2);
}

img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  -o-object-fit: cover;
     object-fit: cover;
  border-radius: 7px;
}

.cd__main main {
  grid-template-columns: 1fr;
  grid-template-rows: 60px;
  grid-gap: 2em;
}
@media screen and (min-width: 600px) {
 .cd__main main {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: -webkit-min-content 1fr;
    grid-template-rows: min-content 1fr;
  }
}

.card {
  width: 90vw;
  max-width: 300px;
}
@media screen and (min-width: 600px) {
  .card {
    width: 40vw;
  }
}

h1 {
  color: #5b6377;
  font-weight: 100;
}
@media screen and (min-width: 600px) {
  h1 {
    grid-column: 1/3;
  }
}

.cd__main main {
  display: grid;
  place-items: center;
  min-height: 600px;
}

body, html {
  color: white;
  background: #333844;
  padding: 0;
  margin: 0;
  min-height: 100vh;
  font-family: "Open Sans", sans-serif;
}

body {
  padding: 1em 0 3em;
  min-height: calc(100vh - 4em);
}

4. Load the jQuery and splitting JS after the HTML structure.

<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script src='https://unpkg.com/splitting/dist/splitting.min.js'></script>

5. Finally, initialize the plugin to activate the splitting effect.

Splitting();

That’s all! hopefully, you have successfully created split card overlay animation. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X