CSS native variables not working in media queries

前端 未结 7 1471
情书的邮戳
情书的邮戳 2020-11-30 19:57

I am trying to use CSS variables in media query and it does not work.

:root {
  --mobile-breakpoint: 642px;
}

@media (max-width: var(--mobile-breakpoint)) {         


        
7条回答
  •  情深已故
    2020-11-30 20:36

    As you can read other answers, still not possible to do so.

    Someone mentioned custom environmental variables (similar to custom css variables env() instead of var()), and the principle is sound, though there are still 2 major issues:

    • weak browser support
    • so far there is no way to define them (but probably will be in the future, as this is so far only an unofficial draft)

提交回复
热议问题