This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
CSS Challenge: Creating a 3D-like Card with a Shadow #2967
Copy link
Copy link
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationweb
Description
This challenge focuses on creating a visually appealing card element using CSS, giving it a subtle 3D effect through box-shadow and subtle gradients. We'll leverage CSS3 properties for this, but the concept could easily be adapted for Tailwind CSS as well.
Description of the Styling
The goal is to build a card that appears to slightly lift off the page. This will be achieved by using a carefully crafted box-shadow to simulate depth and a subtle gradient for a touch of realism. The card will contain a title, some descriptive text, and an image.
Full Code (CSS3)
.card {
width: 300px;
height: 400px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.1); /*Creates the 3D effect*/
overflow: hidden; /*Keeps the image within the card's bounds*/
transition: transform 0.3s ease; /* Adds a smooth hover effect */
}
.card:hover {
transform: translateY(-5px); /*Slight lift on hover*/
box-shadow: 0px 15px 30px rgba(0, 0, 0, 0.2); /*Enhanced shadow on hover*/
}
.card img {
width: 100%;
height: 200px;
object-fit: cover; /*Ensures image covers entire area*/
}
.card-content {
padding: 20px;
}
.card-title {
font-size: 1.5em;
font-weight: bold;
margin-bottom: 10px;
}
.card-description {
font-size: 1em;
line-height: 1.5;
color: #555;
}
/*Example usage with HTML*/
<div class="card">
<img src="your-image.jpg" alt="Card Image">
<div class="card-content">
<h2 class="card-title">Card Title</h2>
<p class="card-description">This is some descriptive text for the card. It can be as long as needed, allowing for flexible content within the design.</p>
</div>
</div>Explanation
box-shadow: This property is key to creating the 3D effect. The values control the horizontal offset, vertical offset, blur radius, and spread radius, along with the color and opacity of the shadow. Adjusting these values allows for fine-tuning the 3D appearance.transition: This provides a smooth animation when hovering over the card.transform: translateY(-5px): This moves the card slightly upwards on hover, further enhancing the 3D illusion.object-fit: cover: This ensures that the image within the card always fills the allocated space while maintaining its aspect ratio.
Resources to Learn More
- MDN Web Docs on CSS Box Shadow: https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
- MDN Web Docs on CSS Transitions: https://developer.mozilla.org/en-US/docs/Web/CSS/transition
- CSS Tricks: (Search for "CSS box shadow" or "CSS card design" on the site) https://css-tricks.com/
Copyrights (c) OpenRockets Open-source Network. Free to use, copy, share, edit or publish.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationweb