Skip to content

Instantly share code, notes, and snippets.

@Kvnbbg
Created September 6, 2024 14:06
Show Gist options
  • Save Kvnbbg/e1f27dcfbd2b9738abf18d6af4531886 to your computer and use it in GitHub Desktop.
Save Kvnbbg/e1f27dcfbd2b9738abf18d6af4531886 to your computer and use it in GitHub Desktop.
CSS Scroll Snap
<div class="wrapper">
<div class="section">
Content 1
</div>
<div class="section bg-blue">
Content 2
</div>
<div class="section bg-green">
Content 3
</div>
<div class="section">
Content 4
</div>
<div class="section bg-blue">
Content 5
</div>
</div>
<script src="https://codepen.io/denic/pen/YzyPzKG.js"></script>
body {
margin: 0;
padding: 0;
}
.wrapper {
height: 100vh;
overflow: auto;
scroll-snap-type: y mandatory;
}
.section {
scroll-snap-align: center;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #de5448;
color: #fff;
font-size: 3em;
}
.bg-blue {
background: #4267b2;
}
.bg-green {
background: #4CAF50;
}
<link href="https://codepen.io/denic/pen/YzyPzKG.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment