Skip to content

Instantly share code, notes, and snippets.

@Git2020104
Last active December 3, 2021 13:43
Show Gist options
  • Save Git2020104/71103833d340dbe612126b8cdf84200f to your computer and use it in GitHub Desktop.
Save Git2020104/71103833d340dbe612126b8cdf84200f to your computer and use it in GitHub Desktop.
3D CSS card
<d<iv class="card-container">
<div class="card">
<h3>Hover me</h3><br>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod maiores sapiente non asperiores deleniti, quos eos placeat corrupti id consequatur ullam accusantium, nesciunt aut fugiat at ipsam harum eveniet dolore.</p>
<div class="layers">
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
</div>
</div>
</d>
<div class="card-container">
<div class="card">
<h3>Hover me</h3><br>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod maiores sapiente non asperiores deleniti, quos eos placeat corrupti id consequatur ullam accusantium, nesciunt aut fugiat at ipsam harum eveniet dolore.</p>
<div class="layers">
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
</div>
</div>
</div>
<script src="https://assets.codepen.io/1948355/twitterButton-2.1.0.js"></script>
@import url("https://fonts.googleapis.com/css?family=Raleway:400,400i,700");
* {
margin: 0 auto;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Raleway, sans-serif;
display: flex;
align-items: center;
min-height: 100vh;
background-color: #ddd;
}
.card-container {
perspective: 50em;
&:nth-child(1) { --bi: repeating-linear-gradient(30deg, #111 0 0.25em, #333 0 1em); }
&:nth-child(2) { --bi: linear-gradient(#555 5em, #0000 3em), linear-gradient(60deg, #880E4F, #1A237E); }
}
.card {
position: relative;
width: 320px;
padding: 3em;
color: #fff;
transform: rotateY(30deg) rotateX(15deg);
transform-style: preserve-3d;
transition: transform 1s;
&:hover {
transform: rotateY(-30deg) rotateX(-15deg);
}
}
.layers {
position: absolute;
left: 0; top: 0;
width: 100%; height: 100%;
transform-style: preserve-3d;
z-index: -1;
}
.layer {
position: absolute;
left: 0; top: 0;
width: 100%; height: 100%;
border-radius: 1em;
background-image: var(--bi);
transform: translateZ(var(--tz));
box-shadow: 0 0 0.5em #000d inset;
@for $i from 0 to 10 {
&:nth-child(#{$i + 1}) {
--tz: #{$i * -4}px;
}
}
&:last-child {
box-shadow: 0 0 0.5em #000d inset, 0 0 5px #000;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment