首页 > 解决方案 > Why CSS.registerProperty is in Javascript but not in CSS?

问题描述

There is a draft of such feature as CSS.registerProperty. In fact it allows to define types for css variables so that browser will be able to extend its abilities about them including animating values.

For me it seems strange that the feature that can be used for css-only perpouses (example) has only javascript representation and can't be used from pure css.

Is there any reason to include it in javascript but not propose same thing for css?


The things that I can't do from css now:

标签: javascriptcssgoogle-chromecss-houdini

解决方案


实际上已经讨论过了,如果事情进展顺利,我们应该能够使用@property规则。

当前的讨论会将您的 js 转换为

@property --alpha {
  syntax: "<number>"; 
  initialValue: 1;
  inherits: true;
})

推荐阅读