Skip to content

Instantly share code, notes, and snippets.

@Kvnbbg
Created September 6, 2024 14:06
Show Gist options
  • Save Kvnbbg/89ddc456b51fdb8ae7fbec56c076577b to your computer and use it in GitHub Desktop.
Save Kvnbbg/89ddc456b51fdb8ae7fbec56c076577b 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