• Stars
    star
    219
  • Rank 177,478 (Top 4 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created almost 2 years ago
  • Updated 8 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Polyfill for CSS Anchor Positioning

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>

If you want to manually apply the polyfill, you can instead import the polyfill function directly from the @oddbird/css-anchor-positioning/dist/css-anchor-positioning-fn.js file.

For build tools such as Vite, Webpack, and Parcel, that will look like this:

import polyfill from '@oddbird/css-anchor-positioning/fn';

The polyfill function returns a promise that resolves when the polyfill has been applied.

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 is animated using transforms), 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)

More Repositories

1

susy

Pre-grid responsive layout toolkit for Sass, now deprecated
SCSS
3,872
star
2

true

Sass unit tests
SCSS
683
star
3

popover-polyfill

Polyfills the HTML popover attribute and showPopover/hidePopover/togglePopover methods onto HTMLElement, as well as the popovertarget and popovertargetaction attributes on <button> elements.
TypeScript
229
star
4

sassdoc-theme-herman

An Odd SassDoc theme.
JavaScript
116
star
5

cascading-color-system

CSS Custom Property color-theming
SCSS
71
star
6

susysite

Source for the new susy.oddbird.net
CSS
59
star
7

css-toggles

CSS Toggles demo and polyfill
JavaScript
57
star
8

css-sandbox

A place to draft & experiment with CSS proposals
Nunjucks
53
star
9

accoutrement

Combined Sass Accoutrement tools, with option for individual module imports
SCSS
36
star
10

accoutrement-color

Color helpers
CSS
32
star
11

blend

More color options for sass…
SCSS
26
star
12

oddcontrast

Svelte
26
star
13

show-when

An element that shows or hides based on provided conditions
JavaScript
22
star
14

slide-deck

Web presentations, as a self-contained web component
JavaScript
19
star
15

oddsite

⛔️ DEPRECATED: Old (unused) OddBird site
HTML
17
star
16

sliiides

An 11ty attempt at web presentations
Nunjucks
17
star
17

odd-browser

A place to explore ideas towards a site-building & networking browser
16
star
18

sass-json-export

JSON exporter for Sass. Based on SassyJSON, by Kitty Giraudel.
SCSS
12
star
19

vuefinder

mia-style slideshows with nuxt
Vue
11
star
20

portfoliyo

A communication tool for teachers and parents
Python
11
star
21

accoutrement-scale

Size and scale helpers for typography and layout
CSS
9
star
22

accoutrement-init

browser normalization and baseline defaults
CSS
6
star
23

greenmud

into the green green mud
JavaScript
6
star
24

accoutrement-maps

Sass map helpers
CSS
5
star
25

oddleventy

Official OddBird Site
Nunjucks
4
star
26

source-element

An exploratory Web Component to conditionally load one of several scripts based on user and browser settings.
JavaScript
4
star
27

PyFly

Python
3
star
28

mlt

Python
3
star
29

polyfill-template

TypeScript
3
star
30

cascade-layers-polyfill-demo

HTML
3
star
31

portfoliyo-landing

A landing page for the Portfoliyo project
JavaScript
2
star
32

accoutrement-type

Font helpers
CSS
2
star
33

susy.oddbird.net

New home for the Susy website
CSS
2
star
34

mozdemos

Demos for Mozilla Developer Channel – https://youtube.com/MozillaDeveloper
HTML
2
star
35

knet

Collecting stories of inspiration for teachers
Python
2
star
36

start-testing-preso

A talk on testing for PyCon US 2013
JavaScript
2
star
37

buntpress

PHP
1
star
38

set-your-code-free-preso

A presentation by Carl Meyer for PyCon 2014
CSS
1
star
39

rectangles

Vue
1
star
40

advanced-python-preso

A presentation by Carl Meyer for ConFoo 2014, on advanced Python techniques.
CSS
1
star
41

mahjongg

Concise scoring summary for Classical European style mahjongg
Ruby
1
star
42

project-templates

JavaScript
1
star
43

accoutrement-layout

Layout helpers in Sass
CSS
1
star
44

herman-test-project

a test project for sassdoc-theme-herman
CSS
1
star
45

bugdash

A "release readiness" and work prioritization dashboard for Bugzilla users.
JavaScript
1
star
46

accoutrement-queries

Media-query helpers
CSS
1
star
47

oddtools

project management tools for oddbird
JavaScript
1
star
48

sass-colors-sample

Sample code for implementing support of CSS color spaces in Sass
SCSS
1
star
49

accoutrement-reset

Reset helpers
CSS
1
star
50

odddocker

A base Docker image for OddBird web projects
Dockerfile
1
star