Created
April 9, 2023 19:44
-
-
Save TahaSh/5cc4328222b77631ba034e204d228b33 to your computer and use it in GitHub Desktop.
Code for "How to Implement Stacking Cards Scrolling Effect in CSS" on YouTube: https://www.youtube.com/watch?v=OY-TySdgXPY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Stacking Cards Scrolling Effect</title> | |
<style> | |
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
} | |
body { | |
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; | |
} | |
.header, .footer { | |
background-color: #001627; | |
color: white; | |
height: 200px; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} | |
.card { | |
width: 100vw; | |
height: 100vh; | |
background: rgb(20, 50, 100, 0.8); | |
color: white; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
position: sticky; | |
top: 0; | |
} | |
.card img { | |
position: absolute; | |
z-index: 1; | |
left: 0; | |
top: 0; | |
width: 100%; | |
height: 100%; | |
object-fit: cover; | |
filter: brightness(0.5); | |
} | |
.card-content { | |
position: absolute; | |
z-index: 2; | |
left: 0; | |
top: 0; | |
width: 100%; | |
height: 100%; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="header">Header</div> | |
<div> | |
<div class="card">Card 1</div> | |
<div class="card"> | |
<img src="https://source.unsplash.com/random/1000x1000" alt="" /> | |
<div class="card-content"> | |
Card 2 | |
</div> | |
</div> | |
<div class="card">Card 3</div> | |
<div class="card">Card 4</div> | |
</div> | |
<div class="footer">Footer</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment