Re: [csswg-drafts] [css-contain] Similar to window.matchMedia(), Container Queries should have a similar method (#6205)

Some experimenting with learning about container-query changes via JS

- MutationObserver
  - Not possible, CSS cannot cause mutations to be observed;  Thought perhaps pseudo-elements might work.. they don't.
- IntersectionObserver
  - Viable perhaps by toggling `display: none` on a "dummy" element.  Limitations: If the container is outside the viewport
  - Example: https://codepen.io/robrez/pen/jOROErL
- ResizeObserver
  - Viable by toggling any css property.  I'm unsure if the CSS engine will always run prior to the resizeObserver callback
  - Example: https://codepen.io/robrez/pen/yLrLyKE
  - Note that many would just use the ResizeObserver w/o any interaction w/ an underlying container query css policy... but the point of this thread is to have something similar to `mediaMatch`.  The things you can do in CSS might be tricky to otherwise detect in JS
  - Note also that `Element.matches` seems like a reasonable _instictive_ "let me try this"... but it will not tolerate any container query

-- 
GitHub Notification of comment by robrez
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6205#issuecomment-1970111751 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 28 February 2024 23:52:26 UTC