DEV Community

Cover image for Card with Hover Details using CSS
Piyush | Coding Torque
Piyush | Coding Torque

Posted on • Originally published at codingtorque.com

Card with Hover Details using CSS

Hello Guys! In this blog, I'm going to explain to you how to make a card with hover details using CSS. This will be a step-by-step guide including HTML and CSS. Let's get started 🚀.

Let's cover HTML Part

We use HTML to make the skeleton of a website. HTML is a markup language.

Now let's import the font awesome CDN in our HTML <head> tag. fontawesome is a library that is used for icons in a website.

<!-- Font Awesome Icons  -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
Enter fullscreen mode Exit fullscreen mode

Now let's import the fonts using Google Fonts API. Below is the code for Poppins Font. Paste the below code in <head> tag.

<!-- Google Fonts  -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
Enter fullscreen mode Exit fullscreen mode

HTML Code

<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Font Awesome Icons  -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
        integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
        crossorigin="anonymous" />

    <!-- Google Fonts  -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">

    <title>Image with onHover details using CSS - @code.scientist x @codingtorque</title>
</head>

<body>
    <div class="container">
        <div class="card">
            <div class="details">
                <h2>Lakes</h2>
                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nobis, sit.</p>
            </div>
        </div>
    </div>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

Output Till Now

Card with Hover Details using CSS

*CSS *

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

body {
    background: black;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 10rem;
}

.container {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

.card {
    background: url('../imgs/sea.jpg') center center / cover;
    border-radius: 10px;
    height: 20rem;
    width: 15rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    z-index: -1;
    cursor: pointer;
    transition: 0.3s;
}

.card:hover {
    transform: scale(1.1);
}

.details {
    position: absolute;
    bottom: -70px;
    left: 0;
    padding: 20px;
    background: linear-gradient(0deg, black, transparent);
    transition: 0.3s ease;
}

.card:hover .details {
    bottom: 0;
}

.details p {
    font-size: 12px;
}
Enter fullscreen mode Exit fullscreen mode

Output Till Now

Card with Hover Details using CSS

Top comments (0)