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

css 变量未生效 #4902

Closed
Bo-Teng opened this issue May 13, 2024 · 2 comments
Closed

css 变量未生效 #4902

Bo-Teng opened this issue May 13, 2024 · 2 comments

Comments

@Bo-Teng
Copy link

Bo-Teng commented May 13, 2024

Hbuilder X 4.08
在App.vue中定义了一个--text-color
image
在其他页面中使用这个变量但是未生效
image
在小程序的开发者工具中能看到page节点下没有看到 --text-color 这个变量,在浏览器中html这个节点有这个变量,但是在**.device-introduction这个节点下没有color:var(--text-color)**

请问是什么原因导致了这个问题

@chasonma
Copy link

不生效可能是 :root 在小程序下是不支持的,可以使用条件编译区分,参考如下:

/* #ifdef H5 */
:root {
  --text-color: red;
}
/* #endif */

/* #ifdef MP */
view {
  --text-color: red;
}
/* #endif */

@Bo-Teng
Copy link
Author

Bo-Teng commented May 24, 2024

好的谢谢

@Bo-Teng Bo-Teng closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants