wxss var不支持全局变量
发布于 5 年前 作者 guiyingqiu 12724 次浏览 来自 问答

经实验,如下似乎在wxss中不支持全局变量哇???


/* # 内部全局声明方式(不支持?) */

:root {
  --primary-color: #167075;
}
.some-text {
   color: var(--primary-color)
}
 
/* # 外部引入方式(不支持?) */
 
/* variables.wxss */
:root {
  --primary-colorred;
}
  
/* app.wxss */
[@import](/user/import) "./variables.wxss";
.some-text {
  color: var(--primary-color)
}
 
 
/* # 局部声明(的确是支持的) */
.some-text {
  --primary-colorred;
  color: var(--primary-color)

}


–这样子就很尴尬。。。

1 回复

变量是支持的,但是 :root 选择器不支持。目前支持的选择器可以参考 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html#%E9%80%89%E6%8B%A9%E5%99%A8

回到顶部