All Projects → nuxodin → Ie11customproperties

nuxodin / Ie11customproperties

Licence: mit
CSS variables (Custom Properties) polyfill for IE11

Projects that are alternatives of or similar to Ie11customproperties

Resize Observer
Polyfills the ResizeObserver API.
Stars: ✭ 540 (-29.41%)
Mutual labels:  polyfill
Polyfill Apcu
This component provides apcu_* functions and the APCUIterator class to users of the legacy APC extension.
Stars: ✭ 629 (-17.78%)
Mutual labels:  polyfill
Fetch
A window.fetch JavaScript polyfill.
Stars: ✭ 25,118 (+3183.4%)
Mutual labels:  polyfill
Gray
Make an image grayscale in all browsers
Stars: ✭ 568 (-25.75%)
Mutual labels:  polyfill
Bootstrap Ie7
Bootstrap 3 CSS for IE7
Stars: ✭ 578 (-24.44%)
Mutual labels:  polyfill
Jsbi
JSBI is a pure-JavaScript implementation of the official ECMAScript BigInt proposal.
Stars: ✭ 663 (-13.33%)
Mutual labels:  polyfill
Object Fit Polyfill
A Javascript polyfill for browsers that don't support the object-fit CSS property.
Stars: ✭ 493 (-35.56%)
Mutual labels:  polyfill
Clipboard Polyfill
📋 Simple copying on the web, with maximum browser compatibility.
Stars: ✭ 748 (-2.22%)
Mutual labels:  polyfill
Polyfill Service
Automatic polyfill service.
Stars: ✭ 5,585 (+630.07%)
Mutual labels:  polyfill
Polyfill Intl Grapheme
This component provides a partial, native PHP implementation of the Grapheme functions from the Intl extension.
Stars: ✭ 690 (-9.8%)
Mutual labels:  polyfill
Darken
🌑 Dark mode made easy
Stars: ✭ 571 (-25.36%)
Mutual labels:  css-variables
Css Paint Polyfill
CSS Custom Paint / Paint Worklet polyfill with special browser optimizations.
Stars: ✭ 575 (-24.84%)
Mutual labels:  polyfill
Create React Context
Polyfill for the proposed React context API
Stars: ✭ 689 (-9.93%)
Mutual labels:  polyfill
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (-26.01%)
Mutual labels:  polyfill
Native Promise Only
A polyfill for native ES6 Promises as close as possible (no extensions) to the strict spec definitions.
Stars: ✭ 708 (-7.45%)
Mutual labels:  polyfill
Undom
🍩 1kb minimally viable DOM Document implementation
Stars: ✭ 496 (-35.16%)
Mutual labels:  polyfill
Text Encoding
Polyfill for the Encoding Living Standard's API
Stars: ✭ 629 (-17.78%)
Mutual labels:  polyfill
Url Search Params
Simple polyfill for URLSearchParams standard
Stars: ✭ 765 (+0%)
Mutual labels:  polyfill
Hyperform
Capture form validation back from the browser
Stars: ✭ 729 (-4.71%)
Mutual labels:  polyfill
Sticky State
StickyState is a high performant module making native position:sticky statefull and polyfilling the missing sticky browser feature
Stars: ✭ 692 (-9.54%)
Mutual labels:  polyfill

CSS Variables Polyfill for IE11

The most complete "Custom Properties polyfill" for Internet Explorer 11.
Used on about 70'000 Live Websites

See the demo!

Discontinued

The IE11 market share is steadily decreasing. I personally have no need to support IE11 anymore.
That's why I have decided to stop working on this project.

Features

  • chaining --bar:var(--foo)
  • fallback var(--color, blue)
  • :focus, :target, :hover
  • handle dynamically added html-content
  • handle dynamically added <style>, <link>-elements
  • js-integration:
    • style.setProperty('--x','y')
    • style.getPropertyValue('--x')
    • getComputedStyle(el).getPropertyValue('--inherited')
  • Houdini’s new API: CSS.registerProperty({name:'--red', inherit:false, initialValue:'#e33'}) (of course not animatable)
  • style-attributes <div ie-style="--foo:bar"...
  • cascade works
  • inheritance works
  • !important on setters and getters (see limitations)
  • inherit, initial, unset and revert keyword for variables
  • SVG support
  • media-queries (redraw on media-changes)
  • transform relative to absolute urls
  • under 4k (min+gzip) and dependency-free

Usage

You only want IE11 to load the polyfill, use this snippet in the head of your html file, it just works:

<script>window.MSInputMethodContext && document.documentMode && document.write('<script src="https://cdn.jsdelivr.net/gh/nuxodin/[email protected]/ie11CustomProperties.min.js"><\/script>');</script>

Help wanted!

How it works

The script makes use of the fact that IE has minimal custom properties support where properties can be defined and read out with the cascade in mind. This is not possible with properties starting with double dashes. .myEl {-ie-test:'aaa'} // only one dash allowed! "-" then you can read it in IE with javascript: getComputedStyle( querySelector('.myEl') )['-ie-test'] In the raw CSS, it replaces for example --foo with -ie-foo. It searches for all rules containing variable getters and setter, remembers the affected selectors so future affected Elements can be found in a mutation observer. Each affected Element gets a uniq class-attribute and its own style-sheet to draw the Element. These are the steps that the script does:

  1. given the CSS
header { --myColor:red; }
main { --myColor:green; }
li { color:var(--myColor); }
  1. rewritten CSS
header { -ie-myColor:red; }
main { -ie-myColor:green; }
li { -ieHasVar-color:var(-ie-myColor); }
  1. find all affected Elements and get their property-values
querySelectorAll('li').forEach(function(){
    var color = getComputedStyle(this).getPropertyValue('--myColor');
    // getPropertyValue is extended to handle custom properties
    // draw_the_Element()
})
  1. draw Elements, this leads in separate rules for each Element
li.iecp-u1 { color:red; }
li.iecp-u2 { color:red; }
li.iecp-u3 { color:green; }
li.iecp-u4 { color:green; }

custom-properties-ie11.png

Limitations

Styles in element-attributes

There is no way to get the raw content of style-attributes in IE11. Use <div style="--color:blue" ie-style="--color:blue"> for this.

Specificity for properties containing "var()"

...is always little higher if vars are not served by root, because each selector gets an additional class-selector eg. #header results in #header.iecp_u44

@import

vars in @import is not supported at the moment

!important

There are problems with !important. I need a minimal, reproducible testcase on https://jsbin.com/

Stylesheets outside the domain

If you'd prefer the polyfill to ignore (not run) on a particular stylesheet add the iecp-ignore tag to the link element.

Tests

See the tests
PRs welcome

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].