Skip to content

add fallback for css variables #7514

Closed
@cedvdb

Description

@cedvdb
- [ X ] feature request

Desired functionality.

Css variables should degrade gracefully on older browsers by having a fallback. This post css plugin does exactly that when started with the option preserve: true. More generally I believe the cli should support the css cutting edge with fallback thanks to cssnext. However variables is what this request is about.

Why ?

If css variable is not supported by a browser it will simply be ignored, meaning that a bunch of css statements won't be applied.

Example

This

:root {
  --color: red;
}

div {
  color: var(--color);
}

should compile to this:

:root {
  --color: red;
}

div {
  color: red;
  color: var(--color);
}

Here is an example that would do just that:

// dependencies
var fs = require("fs")
var postcss = require("postcss")
var customProperties = require("postcss-custom-properties")

// css to be processed
var css = fs.readFileSync("s.css", "utf8")

// process css using postcss-custom-properties
var output = postcss()
  .use(customProperties({ preserve: true }))
  .process(css)
	.css
	
console.log(output)

Metadata

Metadata

Assignees

Labels

P5The team acknowledges the request but does not plan to address it, it remains open for discussionfeatureIssue that requests a new featurehelp wanted

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions