<div class="example">
  <div class="content one"></div>
  <div class="content">
    <div class="box fixed">fixed</div>
  </div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
</div>
<div class="example">
  <div class="content one"></div>
  <div class="content">
    <div class="box sticky">sticky</div>
  </div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
</div>
body {
  display: flex;
}

.example {
  width: 50%;
}
 
.content {
  background: #333;
  height: 300px;
  margin: 1em;
}

.content.one {
  height: 100px;
}

.box {
  width: 100px;
  height: 100px;
  background: limegreen;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2em;
}

.fixed {
  position: fixed;
}

.sticky {
  position: sticky;
  top: 0;
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.