var()
函数可以代替值中的任何部分
元素上的任何属性. var()
函数不能用作
属性名称,选择器或除属性值之外的其他任何内容.
(这样做通常会产生无效的语法,否则会产生一个其值
含义与变量无关.)
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.)
因此,您不能在媒体查询中使用它.
So no, you can't use it in a media query.
那是有道理的.因为您可以设置--mobile-breakpoint
例如到:root
,即<html>
元素,并从那里继承到其他元素.但是媒体查询不是元素,它不能从<html>
继承,因此无法正常工作.
And that makes sense. Because you can set --mobile-breakpoint
e.g. to :root
, that is, the <html>
element, and from there be inherited to other elements. But a media query is not an element, it does not inherit from <html>
, so it can't work.
这不是CSS变量要完成的任务.您可以改用CSS预处理器.
This is not what CSS variables are trying to accomplish. You can use a CSS preprocessor instead.
这篇关于CSS本机变量在媒体查询中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!