<div class="outer">
  <div class="upper">

  </div>
  <div class="clipping-upper">
    <h1 class="hl hl--light">My sticky text</h1>
  </div>
  <span class="hl hl--dark">My sticky text</span>

  <div class="lower"></div>

  <div class="sticky-wrapper">
    <div></div>
  </div>
</div>

<div style="height: 200vh">other content</div>
$text-to-top: 10vh;
$text-to-bottom: 20vh;
$upper-height: 100vh;
$lower-height: 90vh;

.outer {
  position: relative;
  height: #{$upper-height + $lower-height};
  padding: $text-to-top 0 $text-to-bottom 0;
  box-sizing: border-box;
}

.upper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: $upper-height;
  background: #333
    url(https://images.unsplash.com/photo-1612638869944-09bde30478f6?crop=entropy&cs=srgb&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=85);
  background-size: cover;
  background-attachment: fixed;
  z-index: 2;
}

.lower {
  background: grey
    url(https://images.unsplash.com/photo-1611546666752-8794dcd0ab8c?crop=entropy&cs=srgb&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=85);
  background-size: cover;
  background-attachment: fixed;
  height: $lower-height;
  position: absolute;
  top: $upper-height;
  left: 0;
  width: 100%;
  z-index: 0;
}
.hl {
  z-index: 2;
  position: sticky;
  top: $text-to-top;

  font-size: 4rem;
  font-weight: bold;
  display: block;
  margin: 0;
  padding: 0 5rem 0;

  &--light {
    position: fixed;
    z-index: 2;
    color: #fff;
  }

  &--dark {
    z-index: 1;
    color: #000;
  }
}

.clipping-upper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  clip-path: polygon(0% 0%, 100% 0%, 100% $upper-height, 0 $upper-height);
}
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.