Workaround to clip fixed positioned element to parent

by ian_smithz

HTML

<div class="parent-container">
  <div class="parent">
    <div class="child red">Fixed positioned element</div>
  </div>
</div>

CSS

body {
  font: 14px arial;
}

.parent-container {
  position: relative;
  width: 300px;
  height: 200px;
}

.parent {
  position: fixed;
  width: 300px;
  height: 50%;
  background-color: yellow;
  overflow: hidden;
  margin-top: 80px
}

.child {
  position: fixed;
  top: 0;
  padding: 1em;
  background-color: red;
}