Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

CSS Challenge: Creating a 3D-like Card with CSS #2963

@github-actions

Description

@github-actions

This challenge focuses on creating a visually appealing 3D-like card effect using only CSS. We'll achieve this primarily using box-shadows and transforms to simulate depth and perspective. No JavaScript will be used. We will leverage CSS3 properties for this.

Description of the Styling:

The card will be rectangular with rounded corners. The 3D effect will be created by using multiple box-shadows to create a sense of depth and light, making the card appear to be lifted off the page. We'll also use a subtle transform to add to the 3D illusion. The card will have a background color and some simple text content.

Full Code:

<!DOCTYPE html>
<html>
<head>
<title>3D Card</title>
<style>
body {
  background-color: #f0f0f0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.card {
  width: 300px;
  height: 200px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2),
              -5px -5px 10px rgba(255, 255, 255, 0.3); /*Simulates Light and Shadow*/
  transform: perspective(1000px) rotateX(5deg) rotateY(-5deg); /* Adds slight tilt for 3D effect */
  padding: 20px;
}

.card-content {
  text-align: center;
}

.card-title {
  font-size: 1.5em;
  font-weight: bold;
  margin-bottom: 10px;
}
</style>
</head>
<body>
  <div class="card">
    <div class="card-content">
      <h2 class="card-title">My 3D Card</h2>
      <p>This is a simple card with a 3D effect created using CSS.</p>
    </div>
  </div>
</body>
</html>

Explanation:

  • body styling: Centers the card on the page.
  • .card styling: Defines the card's dimensions, background, rounded corners.
  • box-shadow: Two box-shadows are used to simulate light and shadow, creating the 3D illusion. The first creates a darker shadow below and to the right; the second, a lighter highlight above and to the left. Adjust the values to fine-tune the effect.
  • transform: perspective creates a 3D viewing space. rotateX and rotateY slightly tilt the card, enhancing the 3D effect. Adjust the angles for different perspectives.
  • .card-content and .card-title: Simple styling for the card's text content.

Links to Resources to Learn More:

Copyrights (c) OpenRockets Open-source Network. Free to use, copy, share, edit or publish.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationweb

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions