<div>
  <div class="red-parent">
    red-parent
    
    <div class="r-child-1">
      red child 1
    </div>
  </div>
  <div class="blue-parent">
    blue parent
    
    <div class="b-child-1">
      blue child 1
    </div>
    <div class="b-child-2">
      blue child 2
    </div>
  </div>
  <div class="green-parent">
    green parent    
    <div class="g-child-1">
      green child 1
    </div>
  </div>
  
</div>
* {
  color: white;
  font-family: sans-serif;
}

.blue-parent, .blue-parent * {
  background: rgba(0, 0, 255, 0.3);
}

.red-parent, .red-parent * {
  background: rgba(255, 0, 0, 0.3);
}

.green-parent, .green-parent * {
  background: rgba(0, 255, 0, 0.3);
  color: black;
}

.blue-parent, .red-parent, .green-parent {
  padding: 8px;
  height: 300px;
  width: 700px;
}

.red-parent {
  position: absolute;
  top: 20px;
  left: 150px;
  z-index: 1;
}

.r-child-1 {
  position: absolute;
  top: 50px;
  background: #a00a;
  z-index: 2;
  padding: 4px;
}

.blue-parent {
  position: fixed;
  z-index: 0;
  top: 0;
  left: 50px;
}

.b-child-1 {
  position: relative;
  z-index: 100;
  padding: 4px;
}

.b-child-2 {
  position: fixed;
  top: 20px;
  z-index: 1000000;
  padding: 4px;
}

.green-parent {
  position: static;
  z-index: 999;
}

.g-child-1 {
  position: relative;
  z-index: 2;
  left: 200px;
  width: 100px;
  background: rgba(0, 255, 0, 0.7);
  padding: 4px;
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.