<div class="container">
  <div class="content">
    <div class="square"></div>
  </div>
</div>
.container {
  max-width: 500px;
  margin: 1rem auto;
  height: 400px;
  border: 3x solid red;
  overflow: scroll;
}
.content {
  width: 2000px;
  height: 1200px;
  background-color: #ccc;
  display: flex;
  justify-content: center;
  align-items: center;
}
.square {
  width: 30px;
  height: 30px;
  background-color: blue;
  position: sticky;
  top: 20px;
  left: 20px;
  bottom: 20px;
  right: 20px;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.