Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
shadow-container-query-polyfill
Advanced tools
*This repo is based on https://github.com/GoogleChromeLabs/container-query-polyfill with the added enhancement for shadow dom/web components.*
This repo is based on https://github.com/GoogleChromeLabs/container-query-polyfill with the added enhancement for shadow dom/web components.
If you find this work helpful please consider buying me a coffee.
A small (9 kB compressed) polyfill for CSS Container Queries using ResizeObserver
and MutationObserver
supporting the full @container
query syntax:
width: 300
and min-width: 300px
)200px < width < 400px
and width < 400px
)cqw
, cqh
, cqi
, cqb
, cqmin
, and cqmax
) in properties and keyframesnpm install --save shadow-container-query-polyfill
Alternatively, you can use it directly from a CDN:
<script src="https://cdn.jsdelivr.net/npm/shadow-container-query-polyfill@1/dist/shadow-container-query-polyfill.modern.mjs"></script>
For the best user experience, it's recommended that you initially only use the polyfill for content below-the-fold and use @supports
queries to temporarily replace it with a loading indicator until the polyfill is ready to display it:
@supports not (container-type: inline-size) {
.container,
footer {
display: none;
}
.loader {
display: flex;
}
}
You can view a more complete demo here. On sufficiently fast networks and devices, or devices that natively support Container Queries, this loading indicator will never be displayed.
Note Keep in mind that this technique effectively limits impact on FID and CLS, potentially at the expense of LCP. You may see regressions in the latter as a result, particularly on lower end devices or in poor network conditions.
<style>
and same-origin <link>
elements. Inline styles via the style
attribute or CSSOM methods are not polyfilled. Likewise, JavaScript APIs like CSSContainerRule
are not polyfilled, and APIs like CSS.supports()
are not monkey-patched.font-size
in a container without content) may not be detected, or may be detected a frame late on some browsers. Complex sibling CSS selectors aren't supported.calc(...)
in container conditions. Your contribution would be welcome!:where()
The polyfill uses the CSS :where()
pseudo-class to avoid changing the specificity of your rules. This pseudo-class is relatively new, however. If you need to support browsers without it, you will need to append the dummy :not(container-query-polyfill)
pseudo-class to the originating element of every selector under a @container
block:
Before | After |
|
|
This is to ensure the specificity of your rules never changes (e.g. while the polyfill is loading, or on browsers with native support for container queries). On browsers without :where()
supports, rules without the dummy will be ignored.
FAQs
*This repo is based on https://github.com/GoogleChromeLabs/container-query-polyfill with the added enhancement for shadow dom/web components.*
We found that shadow-container-query-polyfill demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.