Quick overview of stacking context

1 min read

Stacking context 決定元素在 z 軸上的排序,常見創建 stacking context 情況:

規則:

With a basic example

<html>
  <body>
    <header style="position: sticky; z-index: 100;">
      <h1>Title</h1>
    </header>
    <section>
      <h2>First section</h2>
      <div>Item 1</div>
      <div>Item 2</div>
    </section>
    <section style="position: absolute;">
      <h2>Second section</h2>
      <div>Item 1</div>
      <div>Item 2</div>
    </section>
  </body>
</html>

References