MadLittleMods / MadLittleMods/postcss-css-variables

Reduce nested calc for IE11

Open
#66 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
JavaScript
Stars
551
Forks
63
PR merge metrics
No merged PRs in 30d

Description

Hello,
I'm using `postcss-css-variables` in combination with cssnext.

Given this (rather naive) css:
```css
:root {
--test1: calc(10vh - 20px);
--test2: calc(var(--test1) * 2);
}
.testNestedCalc {
height: var(--test2);
background-color: red;
}
```

Generates this CSS output:
```css
.testNestedCalc {
height: calc(calc(10vh - 20px) * 2);
background-color: red;
}
```

If I use the cssnext built in custom properties I'll get this output:
```css
.testNestedCalc {
height: calc(20vh - 40px);
background-color: red;
}
```

Nested calc is OK for modern browsers, but ie11 does not understand nested calc.

cssnext uses the [`reduce-css-calc`](https://github.com/MoOx/reduce-css-calc) to remove nested calc. Is there a way to use the same reducer (or something similar) with `postcss-css-variables`?

My postcss config:
```js
plugins = () => {
let result = [
require('postcss-import')({ /* ...options */ }),
require('postcss-url')({ /* ...options */ }),
require('postcss-mixins')({ /* ...options */ }),
require('postcss-cssnext')({
features: {
customProperties: false,
rem: false,
}
}),
require('postcss-css-variables')({ /* ...options */ }),
require('postcss-hexrgba')({ /* ...options */ }),
];
return result;
};
module.exports = {
plugins: plugins()
};
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing postcss-css-variables after custom-property substitution and compare its output with cssnext's reduce-css-calc behavior. Reproduce the supplied nested custom-property example using the shown PostCSS plugin configuration; done means the generated CSS no longer contains nested calc() expressions and remains compatible with IE11.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.