5

I'm working on an Ionic 4 app, and I've run into a strange issue with a fixed position footer inside their .scroll-content class. I could reproduce this without Ionic, so I'm asking the question in a more general sense:

I have a container element (provided by Ionic in my case) which has:

.scroll-content {
    overflow-y: scroll; 
    position: absolute;
    contain: layout size style;
}

Plus some top/bottom/left/right values to position it, they don't impact the problem.

Inside it there is content that is taller than this container, causing the container to scroll, and a footer that I made sticky with position: fixed.

However, the footer doesn't behave as if it's sticky at all unless I remove the "layout" value from the contain property.

let layout = true;
const container = document.querySelector('.scroll-content');

document.getElementById('toggleLayout').addEventListener('click', (e) => {
    layout = !layout;
    if(layout) container.style.contain = 'size style layout';
    else container.style.contain = 'size style';
    
    e.target.innerHTML = `layout: ${layout}`;
});
.scroll-content {
 contain: layout size style;
 left: 0;
 right: 0;
 top: 0;
 bottom: 0;
 position: absolute;
 overflow-y: scroll;
}

li {
  border-bottom: 1px solid #ddd;
  list-style: none;
  padding: 10px;
}

footer {
  background: #eee;
  bottom: 0;
  padding: 20px;
  position: fixed;
  width: 100%;
}
<div class="scroll-content">
<button id="toggleLayout">layout: true</button>
    <ul>
      <li>a</li>
      <li>b</li>
      <li>c</li>
      <li>d</li>
      <li>e</li>
      <li>f</li>
      <li>g</li>
      <li>h</li>
      <li>i</li>
      <li>j</li>
      <li>k</li>
      <li>l</li>
      <li>m</li>
      <li>n</li>
      <li>p</li>
      <li>o</li>
      <li>q</li>
      <li>r</li>
      <li>s</li>
    </ul>
    <footer>Footer</footer>
</div>

For now I'd like to assume Ionic added this class with a purpose, so I prefer not to override it. Is the broken position: fixed behavior expected? If so, what can I do to work around it and make my footer fixed again?

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
  • This is a known issue in Chrome. Works correctly in Firefox. – BoltClock Nov 05 '18 at 14:16
  • @BoltClock thanks! Do you have any sources? It's so hard to properly google these terms. – Stephan Muller Nov 05 '18 at 14:36
  • 1
    Actually, this might be a new issue. All the existing sources I've found are really discussing the fact that contain: layout makes an element the containing block of fixed position descendants. I don't think being the containing block should cause fixed position elements to stop becoming fixed with respect to the element itself - unless I'm misunderstanding containing blocks. – BoltClock Nov 05 '18 at 14:49
  • 1
    https://github.com/ionic-team/ionic/issues/16780 – Redwolf Dec 20 '18 at 17:44

0 Answers0