Position fixed sticks to parent absolute
<p>I have an interesting problem. The CSS property position, value fixed, is supposedly relative to the browser window. Yet, somehow, in this code it sticks to the parent which is absolute, when scrolled. How and why?</p>

<p>HTML:</p>

<pre><code>&lt;section&gt;
  &lt;div class="container"&gt;
    &lt;div class="wrapper"&gt;
      &lt;div class="content"&gt;
      &lt;div class="bar"&gt;      
      &lt;/div&gt;
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a quam ultrices libero convallis consequat eget non eros. Proin in velit ullamcorper, tristique leo id, tempus ipsum. Mauris in nisl at tortor vulputate dictum. Morbi at leo non ante euismod gravida ut sit amet massa. Suspendisse potenti. Fusce nec ultricies arcu. Sed at nunc turpis. Vivamus suscipit eu mi mollis tempor. Nullam ut urna libero. Duis finibus egestas erat, non faucibus sem placerat a. Curabitur sollicitudin porttitor urna, a eleifend diam ultrices non. Praesent lacus lectus, volutpat scelerisque lacus quis, vehicula eleifend dui. Praesent eget est magna. Sed faucibus tellus diam, commodo ultricies ipsum pulvinar et. Phasellus nec blandit tortor, eget facilisis tellus. Nulla vitae ornare neque.
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;section&gt;
  &lt;div class="container"&gt;
    &lt;div class="wrapper"&gt;
      &lt;div class="content"&gt;
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a quam ultrices libero convallis consequat eget non eros. Proin in velit ullamcorper, tristique leo id, tempus ipsum. Mauris in nisl at tortor vulputate dictum. Morbi at leo non ante euismod gravida ut sit amet massa. Suspendisse potenti. Fusce nec ultricies arcu. Sed at nunc turpis. Vivamus suscipit eu mi mollis tempor. Nullam ut urna libero. Duis finibus egestas erat, non faucibus sem placerat a. Curabitur sollicitudin porttitor urna, a eleifend diam ultrices non. Praesent lacus lectus, volutpat scelerisque lacus quis, vehicula eleifend dui. Praesent eget est magna. Sed faucibus tellus diam, commodo ultricies ipsum pulvinar et. Phasellus nec blandit tortor, eget facilisis tellus. Nulla vitae ornare neque.
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
</code></pre>

<p>CSS:</p>

<pre><code>section {
    width: 100%;
    display: block;
    max-width: none;
    height: 100vh !important;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    position: relative;
}

section .content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
}

section .wrapper {
    max-width: 770px;
    margin: 0 auto 50px;
    text-align: center;
    padding: 0 25px 50px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

.bar {
  display: block;
  width: 100%;
  height: 30px;
  background: #00aeef;
  margin-bottom: 40px;
}

.bar.fixed {
  position: fixed;
  top: 0;
}
</code></pre>

<p>jQuery:</p>

<pre><code>$(window).scroll(function() {
    var scrollPos = $(document).scrollTop();
    if(scrollPos &gt; $('.bar').offset().top) {
        $('.bar').addClass('fixed');
    } else {
  $('.bar').removeClass('fixed');
}
}).scroll();
</code></pre>

<p><a href="https://jsfiddle.net/bg6cqcfp/1/" rel="nofollow">https://jsfiddle.net/bg6cqcfp/1/</a></p>