.container
  .container__inner overflow-x:hidden
    .stickyBox
      span position:sticky
View Compiled
body {
  background: #000;
  padding: 0;
}

.container {
  overflow: visible scroll; //overflow-x overflow-y
  max-width: 300px;
  height: 90vh;
  margin: auto;
  background: #fff;
}

.container__inner {
  overflow-x: hidden;
  height: 300vh;
}

.stickyBox {
  position: sticky;
  top: 0;
  width: 100px;
  height: 100px;
  margin: 100px auto 0;
  background: skyblue;
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.