Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce nested calc for IE11 #66

Open
leifoolsen opened this issue Jan 13, 2018 · 3 comments
Open

Reduce nested calc for IE11 #66

leifoolsen opened this issue Jan 13, 2018 · 3 comments

Comments

@leifoolsen
Copy link

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

Given this (rather naive) css:

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

Generates this CSS output:

.testNestedCalc {
  height: calc(calc(10vh - 20px) * 2);
  background-color: red;
}

If I use the cssnext built in custom properties I'll get this output:

.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 to remove nested calc. Is there a way to use the same reducer (or something similar) with postcss-css-variables?

My postcss config:

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()
};
@MadLittleMods
Copy link
Owner

MadLittleMods commented Feb 4, 2018

@leifoolsen Sorry for the delay, PR welcome! Probably somewhere around here (relevant code),

return replaceValue;

@MadLittleMods MadLittleMods changed the title nested calc and IE11 Reduce nested calc for IE11 Feb 4, 2018
@QJan84
Copy link

QJan84 commented May 22, 2019

Is there a solution?

@MadLittleMods
Copy link
Owner

@QJan84 https://github.com/postcss/postcss-calc looks like it will work. Here is the test around nested calcs there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants