Skip to content

Instantly share code, notes, and snippets.

@nomyfan
Created December 13, 2020 14:44
Show Gist options
  • Save nomyfan/e4a93374c3a4663deee5a74a1248b438 to your computer and use it in GitHub Desktop.
Save nomyfan/e4a93374c3a4663deee5a74a1248b438 to your computer and use it in GitHub Desktop.
Sticky overlap title example
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sticky overlap title example</title>
<style>
.sticky-title {
position: sticky;
top: 2em;
color: goldenrod;
font-size: 2em;
background-color: white;
display: inline-block;
z-index: 1;
/*z-index:1 must be set for the reason that the opacity property is applied to the style named content-box through animation.
If you don't do this, content-box styled elements will be front of the sticky-title styled elements while animating, because
opacity property also make elements to create a stacking context.
*/
}
.content-box {
height: 500px;
background-color: sienna;
animation-name: fadeIn;
animation-duration: 2s;
}
</style>
</head>
<body>
<div class="sticky-title">Title1</div>
<div class="content-box"></div>
<div class="sticky-title">Title2</div>
<div class="content-box"></div>
<div class="sticky-title">Title3</div>
<div class="content-box"></div>
<div class="sticky-title">Title4</div>
<div class="content-box"></div>
<div class="sticky-title">Title5</div>
<div class="content-box"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment