Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oddbird/css-anchor-positioning

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oddbird/css-anchor-positioning

Polyfill for the proposed CSS anchor positioning spec

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
increased by55.82%
Maintainers
3
Weekly downloads
 
Created
Source

CSS Anchor Positioning Polyfill

Build Status

Netlify Status

WPT results

Browser Support

  • Firefox 54+
  • Chrome 51+
  • Edge 79+
  • Safari 10+

Getting Started

To use the polyfill, add this script tag to your document <head>:

<script type="module">
  if (!("anchorName" in document.documentElement.style)) {
    import("https://unpkg.com/@oddbird/css-anchor-positioning");
  }
</script>

You can view a more complete demo here.

Configuration

The polyfill accepts one argument (type: boolean, default: false), which determines whether anchor calculations should update on every animation frame (e.g. when the anchor element moves), in addition to always updating on scroll/resize. While this option is optimized for performance, it should be used sparingly.

<script type="module">
  if (!("anchorName" in document.documentElement.style)) {
    const { default: polyfill } = await import("https://unpkg.com/@oddbird/css-anchor-positioning/dist/css-anchor-positioning-fn.js");

    polyfill(true);
  }
</script>

When using the default version of the polyfill that executes automatically, this option can be set by setting the value of window.UPDATE_ANCHOR_ON_ANIMATION_FRAME.

<script type="module">
  if (!("anchorName" in document.documentElement.style)) {
    window.UPDATE_ANCHOR_ON_ANIMATION_FRAME = true;
    import("https://unpkg.com/@oddbird/css-anchor-positioning");
  }
</script>

Limitations

This polyfill doesn't (yet) support the following:

  • anchor-default property
  • anchor-scroll property
  • anchor functions with implicit anchor-element
  • automatic anchor positioning: anchor functions with auto or auto-same anchor-side
  • dynamically added/removed anchors or targets
  • anchors or targets in the shadow-dom
  • tracking the order of elements in the top-layer to invalidate top-layer target elements from anchoring to succeeding top-layer anchors. See this WPT for an example.
  • anchor functions assigned to inset-* properties or inset shorthand property
  • vertical/rtl writing-modes (partial support)
  • absolutely-positioned targets with grid-column/grid-row/grid-area in a CSS Grid layout
  • @position-fallback where targets in a CSS Grid layout overflow the grid area but do not overflow the containing block
  • @position-fallback where targets overflow their inset-modified containing block, overlapping the anchor element
  • anchors in multi-column layouts
  • anchor functions used as the fallback value in another anchor function
  • anchor functions assigned to bottom or right properties on inline targets whose offset-parent is inline with clientHeight/clientWidth of 0 (partial support -- does not account for possible scrollbar width)

Keywords

FAQs

Package last updated on 27 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc