Workaround for CSS variables in IE?

2020-02-19 04:20发布

I'm currently developing a web application in Outsystems in which I have the need to customize the CSS, in which I'm using variables. I need to guarantee the app works cross-browser, including in Internet Explorer. IE doesn't support CSS variables, as you can see in the picture below from this source.

Since I have to use CSS variables, is there any workaround for the usage of variables in IE?

9条回答
来,给爷笑一个
2楼-- · 2020-02-19 04:46

In case someone comes across this, has a similar issue where I had it set like this.

a {
  background: var(--new-color);
  border-radius: 50%;
}

I added the background colour before the variable so if that didn't load it fell back on the hex.

a {
  background: #3279B8;
  background: var(--new-color);
  border-radius: 50%;
}
查看更多
叼着烟拽天下
3楼-- · 2020-02-19 04:56
body {
  --text-color : red; /* --text-color 정의 */
}    

body {
   color: var(--text-color, red); /* --text-color 정의되지 않으면 red로 대체됨 */
}

body {
   color: var(--text-color, var(--text-color-other, blue));
   /* --text-color, --text-color-other 가 정의되지 않으면 blue로 대체됨 */
}
查看更多
啃猪蹄的小仙女
4楼-- · 2020-02-19 04:58

There is no way yet in "normal" css but take a look at sass/scss or less.

here is a scss example

$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;
}
查看更多
登录 后发表回答