How to force integer in CSS Variable?

旧巷老猫 提交于 2019-12-08 18:14:25

The spec allows using custom property values as numeric values.

But the context your var() expression appears isn't CSS at all. It's Sass. For obvious reasons, the spec doesn't cover non-standard syntax, or preprocessors. It's unreasonable to assume that a var() expression is going to work in that context.

In fact, custom properties only work in property declarations. They don't work anywhere else. The spec states this here:

The var() function can be used in place of any part of a value in any property on an element. The var() function can not be used as property names, selectors, or anything else besides property values. (Doing so usually produces invalid syntax, or else a value whose meaning has no connection to the variable.)

Since this is a Sass loop, I don't see any reason not to use Sass variables:

$ile: 10;

@for $i from 0 to $ile { }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!