postcss / postcss-custom-properties

Use Custom Properties in CSS
https://postcss.github.io/postcss-custom-properties
MIT License
597 stars 77 forks source link

Retrieving custom property values with `getPropertyValue` doesn't work in IE11 #168

Open toufali opened 5 years ago

toufali commented 5 years ago

Trying to access custom properties set in :root does not seem to work on IE11: getComputedStyle(document.documentElement).getPropertyValue('--my-var') returns empty string despite confirming --my-var is properly set.

Works as expected on Edge and all modern browsers.

BrentWMiller commented 5 years ago

@HandsomeMedia IE11 doesn't support CSS variables. Ref: https://caniuse.com/#search=css%20variable

toufali commented 5 years ago

@BrentWMiller yes, but isn't that the main point of PostCSS custom properties - to polyfill for browsers that don't support it?

qkevinto commented 5 years ago

@HandsomeMedia, PostCSS Custom Properties does not polyfill anything but rather transforms your CSS to add in a fallback declaration for the usage of CSS custom properties during build time. PostCSS itself is a CSS transformation/postprocessing tool that's used during build time and has no effect on the client's browser.

toufali commented 5 years ago

Okay, let me rephrase then: Shouldn't PostCSS transform the :root CSS to add a fallback declaration in IE11, so that we can access it via getComputedStyle(document.documentElement).getPropertyValue('--my-var')?

coolemur commented 4 years ago

I have the same issue.

I'm thinking of giving https://www.npmjs.com/package/css-vars-ponyfill a go but not sure if this will work as expected in combination with custom properties.

More ideas are welcome. Thank you.

coolemur commented 4 years ago

Just tested ponyfill. Didn't work on IE11 (doesn't set/get css variables from js).

spiess-demos commented 4 years ago

@coolemur the css-vars-ponyfill module provides javascript access to all custom properties in a callback: https://github.com/jhildenbiddle/css-vars-ponyfill/issues/85#issuecomment-521771857