top of page
  • Writer's pictureDark CSS

Elevate Your Web Design with Captivating Hover Effects


CSS Card After Effect


Introduction:

In today's digital landscape, creating engaging and interactive user experiences is crucial for web designers. One powerful technique to achieve this is by incorporating captivating hover effects into elements on a webpage. These effects not only enhance visual appeal but also encourage user interaction and engagement. In this article, we'll explore how to craft a stunning hover effect for cards using HTML and CSS, allowing you to elevate your web design skills and captivate your audience.


Setting Up the Project

Before delving into the code, let's start by creating the necessary files for our project. We'll need two files: index.html to define the structure of our webpage and style.css to add styling and animations.


HTML Code:

Our HTML code serves as the blueprint for our card layout. It consists of essential elements such as the card container, image, and content overlay. Let's break down each element's role in our design:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Card After Effect On Hover</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="card">
        <img src="images/image.png" alt="">
        <div class="content">
            <h3>It's Dark CSS</h3>
            <p>
                We are here to provide you FREE web development tutorials
            </p>
            <!-- Social media icons will go here -->
        </div>
    </div>
</body>
</html>

<div class="card">: This container holds our card element.

<img src="images/image.png" alt="">: The image tag displays an image within the card.

<div class="content">: This div serves as the content overlay that appears upon hovering over the card. <h3> and <p>: These tags contain text content within the overlay, providing additional information.




CSS Styling:

Now, let's bring our design to life with CSS styling. Each line of CSS code defines the appearance and behavior of our elements, from dimensions to hover effects. Here's the CSS code along with explanations:

/* Importing Google Fonts and setting default styles */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300&family=Schibsted+Grotesk:wght@600&display=swap');
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

/* Styling the card container */
.card {
    position: relative;
    width: 320px;
    height: 440px;
    border: 5px solid #2885fe;
    overflow: hidden;
    box-shadow: 5px 20px 10px rgba(0, 0, 0, 0.1);
}

/* Styling the card image */
.card img {
    width: 103%;
    display: block;
}

/* Styling the content overlay */
.content {
    width: 100%;
    height: 0%;
    background: linear-gradient(rgba(0,0,0,0.6), #2885fe);
    position: absolute;
    bottom: 0;
    left: 0;
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    color: #fff;
    padding: 0 30px;
    text-align: center;
    transition: height 0.5s;
}

/* Styling content text */
.content p {
    letter-spacing: 1px;
    font-size: 14px;
}

.content h3 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
}

/* Styling social media icons */
.social-icons {
    display: flex;
    flex-direction: row;
}

.social-icons span {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
    width: 40px;
    background-color: #fff;
    border-radius: 50%;
    cursor: pointer;
    margin: 20px 10px;
}

.social-icons a {
    font-size: 24px;
    color: #000;
    text-decoration: none;
    display: flex;
    align-items: center;
}

/* Hover effect */
.card:hover .content {
    height: 100%;
}

Now, let's delve deeper into the CSS code and understand each style rule's purpose:

@import url(...): This rule imports Google Fonts to style our text. We're using the Poppins font for a modern and clean look.

*: Sets default styles for all elements, including removing default padding and margin and applying the chosen font family.

.card: Styles the container for the card, defining its dimensions, border, overflow behavior, and box shadow to create a visually appealing card-like appearance.

.card img: Styles the image within the card, ensuring it fits properly within the container and maintains its aspect ratio.

.content: Styles the content overlay, specifying its dimensions, background gradient, position, text color, and transition effects to create a smooth animation when the overlay expands.

.content p and .content h3: Further styles the text content within the overlay, defining font size, weight, and spacing for improved readability.

.social-icons and .social-icons span: Styles the social media icons within the content overlay, setting dimensions, background color, and cursor behavior to enhance interactivity.

.card:hover .content: Defines the hover effect, causing the content overlay to expand in height when the card is hovered over, revealing the additional content.


Conclusion:

Mastering the art of crafting captivating hover effects with HTML and CSS empowers you to transform static web elements into dynamic and engaging components. By understanding and applying CSS styling effectively, you can enhance your web designs and captivate your audience with immersive interactions. Feel free to download the complete source code provided below and embark on your journey to creating mesmerizing hover effects in your projects.

Elevate your web design, mesmerize your users, and unleash your creativity with captivating hover effects. Happy coding!



Card Hover Effect
.zip
Download ZIP • 6.43MB

Related Posts

See All

Dark CSS

bottom of page