[{"data":1,"prerenderedAt":6},["ShallowReactive",2],{"post-content-position-fixed-not-working-transformed-ancestor":3},{"content":4,"lastModified":5},"\u003Cp>The bug report had a screenshot and five words: the drawer is in a box.\u003C\u002Fp>\n\n\u003Cp>It was. \u003Ccode>position: fixed; inset: 0\u003C\u002Fcode> inside a card component. On my machine the drawer covered the screen. In production it covered a 320px rectangle in the middle of the page, and scrolled up with the content instead of staying put. Nobody had touched the drawer. A week earlier someone put a hover animation on the card wrapper.\u003C\u002Fp>\n\n\u003Cp>Third time I have run into this one. Numbers instead of adjectives from here.\u003C\u002Fp>\n\n\u003Ch2>The viewport is only the default containing block\u003C\u002Fh2>\n\n\u003Cp>Offsets on a fixed element resolve against a containing block, and normally that block is the viewport. That is why \u003Ccode>top: 0\u003C\u002Fcode> means the top of the screen. Put the right property on an ancestor and the ancestor becomes the containing block instead. Your \u003Ccode>inset: 0\u003C\u002Fcode> now means the ancestor's edges.\u003C\u002Fp>\n\n\u003Cp>The answers I found when this first bit me all list transform, filter, perspective and will-change. Correct, and incomplete in ways that cost me an afternoon.\u003C\u002Fp>\n\n\u003Cp>\u003Cimg src=\"https:\u002F\u002Fimages.pexels.com\u002Fphotos\u002F37341519\u002Fpexels-photo-37341519.jpeg?auto=compress&amp;cs=tinysrgb&amp;w=1200\" alt=\"Wooden nesting dolls lined up with each smaller doll sitting inside the one before it\" loading=\"lazy\">\u003C\u002Fp>\n\n\u003Ch2>What actually triggers it\u003C\u002Fh2>\n\n\u003Cp>I dropped a 10px fixed probe with \u003Ccode>top: 0; left: 0\u003C\u002Fcode> inside a 300px div, one property at a time, and read \u003Ccode>getBoundingClientRect()\u003C\u002Fcode>. A probe at 0,0 means the viewport still owns it. Chrome 157, headless, macOS:\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode>nothing                        viewport\ntransform: none                viewport\ntransform: scale(1)            TRAPPED\ntransform: translateX(0)       TRAPPED\ntransform: rotate(0deg)        TRAPPED\ntranslate: 0 0                 TRAPPED\nscale: 1                       TRAPPED\nrotate: 0deg                   TRAPPED\nfilter: none                   viewport\nfilter: blur(0px)              TRAPPED\nfilter: opacity(1)             TRAPPED\nbackdrop-filter: blur(2px)     TRAPPED\nperspective: 1000px            TRAPPED\nwill-change: transform         TRAPPED\nwill-change: opacity           viewport\ncontain: layout                TRAPPED\ncontain: paint                 TRAPPED\ncontain: content               TRAPPED\ncontainer-type: inline-size    viewport\ncontent-visibility: auto       TRAPPED\noffset-path                    TRAPPED\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>Identity values count. \u003Ccode>transform: scale(1)\u003C\u002Fcode> changes nothing on screen and still takes the containing block, and so do \u003Ccode>translateX(0)\u003C\u002Fcode> and \u003Ccode>rotate(0deg)\u003C\u002Fcode>. The check is whether the property is \u003Ccode>none\u003C\u002Fcode>, not whether the matrix does anything. That is how a \u003Ccode>translateZ(0)\u003C\u002Fcode> added for GPU compositing breaks a modal two components away.\u003C\u002Fp>\n\n\u003Cp>The longhands hide from the Styles panel. \u003Ccode>translate: 0 0\u003C\u002Fcode>, \u003Ccode>scale: 1\u003C\u002Fcode> and \u003Ccode>rotate: 0deg\u003C\u002Fcode> trap the child the same way, and computed \u003Ccode>transform\u003C\u002Fcode> still reads \u003Ccode>none\u003C\u002Fcode>. Nothing shows up in DevTools, and nothing stops you from typing those longhands by hand.\u003C\u002Fp>\n\n\u003Cp>Containment does it too. \u003Ccode>contain: layout\u003C\u002Fcode>, \u003Ccode>contain: paint\u003C\u002Fcode> and \u003Ccode>contain: content\u003C\u002Fcode> all trap, and so does \u003Ccode>content-visibility: auto\u003C\u002Fcode>, which is exactly what you add to keep a long list scrolling smoothly. \u003Ccode>container-type: inline-size\u003C\u002Fcode> did not trap in Chrome 157, which surprised me after \u003Ca href=\"\u002Fposts\u002Fcss-container-queries-guide\u002F\">writing about container queries\u003C\u002Fa>. I did not test Safari, so treat that line as Chrome-only.\u003C\u002Fp>\n\n\u003Ch2>Four symptoms and a one-line tell\u003C\u002Fh2>\n\n\u003Cul>\n\u003Cli>An \u003Ccode>inset: 0\u003C\u002Fcode> overlay covers the card instead of the screen and starts a few pixels in. My ancestor had a 352x152 border box with a 6px border; the overlay measured 340x140 sitting 6px inside. Fixed offsets skip the border.\u003C\u002Fli>\n\u003Cli>\u003Ccode>bottom: 0\u003C\u002Fcode> sticks to the card's bottom edge. Against the ancestor's bottom, not the window's.\u003C\u002Fli>\n\u003Cli>The child scales with the parent. A 20px probe measured 10x10 under \u003Ccode>transform: scale(0.5)\u003C\u002Fcode> on the ancestor. That is the \"why is my close button tiny and drifting\" bug.\u003C\u002Fli>\n\u003Cli>Scrolling drags it along. Probe top went from 890 to 690 after a 200px scroll, while the untrapped probe sat at 0 the whole time.\u003C\u002Fli>\n\u003C\u002Ful>\n\n\u003Cp>The cheap tell is \u003Ccode>el.offsetParent\u003C\u002Fcode>. On a fixed element it is normally \u003Ccode>null\u003C\u002Fcode>. Once an ancestor owns the containing block it comes back as an element. Not always the guilty one, but enough to know the viewport is out of the picture.\u003C\u002Fp>\n\n\u003Ch2>Finding the ancestor instead of guessing\u003C\u002Fh2>\n\n\u003Cp>Toggling styles in DevTools until something moves works, and I have done it enough times to want a shortcut.\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode class=\"language-js\">function findFixedTrap(el) {\n  const contain = ['layout', 'paint', 'content', 'strict'];\n  for (let n = el.parentElement; n &amp;&amp; n !== document.documentElement; n = n.parentElement) {\n    const cs = getComputedStyle(n);\n    const hits = [];\n    if (cs.transform !== 'none') hits.push('transform');\n    if (cs.filter !== 'none') hits.push('filter');\n    if ((cs.backdropFilter || 'none') !== 'none') hits.push('backdrop-filter');\n    if (cs.perspective !== 'none') hits.push('perspective');\n    if (cs.translate !== 'none') hits.push('translate');\n    if (cs.scale !== 'none') hits.push('scale');\n    if (cs.rotate !== 'none') hits.push('rotate');\n    if (cs.contain.split(' ').some((v) =&gt; contain.includes(v))) hits.push('contain');\n    if (\u002Ftransform|perspective|filter\u002F.test(cs.willChange)) hits.push('will-change');\n    if (cs.contentVisibility === 'auto') hits.push('content-visibility');\n    if (hits.length) return { node: n, hits };\n  }\n  return null;\n}\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>One call on the broken overlay names the wrapper. I keep that in \u003Ca href=\"\u002Fsnippetark\u002F\" rel=\"noopener noreferrer\" target=\"_blank\">Snippet Ark\u003C\u002Fa> with the rest of my debugging one-offs, because retyping it from memory at 11pm is how typos happen. What the function cannot tell you is which ancestor you are allowed to change. That is a product decision.\u003C\u002Fp>\n\n\u003Ch2>Fixes that hold\u003C\u002Fh2>\n\n\u003Cp>The popular advice is to remove the transform. That is often true, and often the transform is the animation, which leaves you with no advice at all.\u003C\u002Fp>\n\n\u003Cp>Move the element out of the subtree. A React portal or a Vue Teleport to \u003Ccode>body\u003C\u002Fcode> puts the drawer where no ancestor can reach it. Portaling into another wrapper that has its own transform puts you back in the same bug with less hair.\u003C\u002Fp>\n\n\u003Cp>Use the top layer. \u003Ccode>&lt;dialog&gt;\u003C\u002Fcode> with \u003Ccode>showModal()\u003C\u002Fcode> renders in the top layer, which puts it beyond the reach of ordinary ancestors. I put a probe inside a fixed child of a dialog nested in a \u003Ccode>translateX(30px)\u003C\u002Fcode> wrapper and measured 0,0. The transform never reached it. You also get focus trapping and an inert background, which is more than most hand-rolled overlays manage.\u003C\u002Fp>\n\n\u003Cp>Keep the animation and drop the trap. Do not leave \u003Ccode>will-change\u003C\u002Fcode> on the element after an entrance animation finishes. \u003Ccode>will-change: opacity\u003C\u002Fcode> leaves the viewport alone, \u003Ccode>will-change: transform\u003C\u002Fcode> does not. And if the animation is a fade, ask whether a transform needs to be involved at all.\u003C\u002Fp>\n\n\u003Cp>The last measurement surprised me. I paused a \u003Ccode>translateX\u003C\u002Fcode> keyframe at halfway, computed transform \u003Ccode>matrix(1, 0, 0, 1, 100, 0)\u003C\u002Fcode>, child trapped. Then I paused another one at 0%: \u003Ccode>matrix(1, 0, 0, 1, 0, 0)\u003C\u002Fcode>, child still trapped. An identity matrix from an attached animation traps like any other. So a wrapper that merely has an animation attached stays broken while that animation sits at its first frame doing nothing visible.\u003C\u002Fp>\n\n\u003Cp>If you have fought \u003Ca href=\"\u002Fposts\u002Fcss-position-sticky-not-working\u002F\">sticky elements that refuse to stick\u003C\u002Fa>, it is the same class of problem. Something upstream changed the box you are being positioned against. My notes on \u003Ca href=\"\u002Fposts\u002Fz-index-not-working-stacking-context\u002F\">z-index that will not stack\u003C\u002Fa> came out of the same week.\u003C\u002Fp>\n","2026-11-22",1795678594075]