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 the HTML part
HTML is a markup language. We use HTML to make the skeleton of a website.
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.
<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" />
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">
Now let's design the container in our `
` tag. In the below HTML code, we have created a container that contains the div which is an image card, in that card we have a details div which holds the heading and details of the card.<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>
Here is the Final 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>
Output Till Now
Let's understand CSS Part
In the below CSS code,
- We declare a * selectors to set the font Poppins that we have imported in our head tag.
- Next we declare a body selector which consists of styles for dark mode and aligns all elements in the body to the center.
- Next, we have a card that has a background property for our card image, border-radius property for rounded corners, height, width, z-index, flex, etc. basic properties.
- Next, we use the `transform: scale(1.3);` property to make a zoom effect on the image on hover.
- Next, we use the linear-gradient property on the background to make a shadow effect at the bottom of the details.
* {
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;
}
Output Till Now
If you want me to code any project or post any specific post,
feel free to DM me at IG @code.scientist or @codingtorque
If you have any doubt or any project ideas feel free to
Contact Us
Hope you find this post helpful💖
Written by: Coding Torque | Piyush Patil
Follow us on Instagram for more projects like
this👨💻