<div class="premium-space">
<div class="holo-card">
<div class="card-content">
<h2 class="dynamic-title">Quantum Tech</h2>
<p class="dynamic-subtitle">Interactive Element</p>
</div>
<!-- This empty div is the magic layer for our holographic reflection -->
<div class="glare"></div>
</div>
</div>
/* Centers everything and creates a dark, premium background */
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #050505;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: white;
}
/* This creates the "camera lens" so the 3D effect has depth */
.premium-space {
perspective: 1000px;
}
/* The actual card layout */
.holo-card {
width: 320px;
height: 450px;
background: linear-gradient(135deg, #1a1a24, #121218);
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.1);
position: relative;
overflow: hidden;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
/* These variables will be updated by our JavaScript later */
transform: rotateY(var(--rotate-y, 0deg)) rotateX(var(--rotate-x, 0deg));
transition: transform 0.1s ease-out; /* Makes the movement smooth */
transform-style: preserve-3d;
}
.card-content {
position: absolute;
bottom: 30px;
left: 30px;
z-index: 2;
/* Pushes the text slightly out towards the user for a 3D pop */
transform: translateZ(50px);
}
.dynamic-title {
margin: 0;
font-size: 2rem;
letter-spacing: 2px;
text-transform: uppercase;
background: linear-gradient(to right, #00f2fe, #4facfe);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.dynamic-subtitle {
margin: 5px 0 0 0;
font-size: 0.9rem;
color: #888;
}
/* The glowing holographic reflection */
.glare {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: radial-gradient(
circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
rgba(255, 255, 255, 0.15),
transparent 50%
);
z-index: 1;
pointer-events: none; /* Ensures the mouse interacts with the card, not the glare */
}
// Grab the card element from our HTML
const card = document.querySelector('.holo-card');
// When the mouse moves over the card, run this calculation
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
// Find the exact X and Y coordinates of the mouse inside the card
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Calculate the center of the card
const centerX = rect.width / 2;
const centerY = rect.height / 2;
// Determine how far the mouse is from the center (to figure out how much to tilt)
const rotateX = ((y - centerY) / centerY) * -15; // Max tilt of 15 degrees
const rotateY = ((x - centerX) / centerX) * 15;
// Send these calculations back to the CSS variables we created
card.style.setProperty('--rotate-x', `${rotateX}deg`);
card.style.setProperty('--rotate-y', `${rotateY}deg`);
card.style.setProperty('--mouse-x', `${(x / rect.width) * 100}%`);
card.style.setProperty('--mouse-y', `${(y / rect.height) * 100}%`);
});
// When the mouse leaves the card, smoothly snap everything back to center
card.addEventListener('mouseleave', () => {
card.style.setProperty('--rotate-x', '0deg');
card.style.setProperty('--rotate-y', '0deg');
card.style.setProperty('--mouse-x', '50%');
card.style.setProperty('--mouse-y', '50%');
});
No comments yet. Be the first!