Git Product home page Git Product logo

Comments (12)

MoOx avatar MoOx commented on July 23, 2024

According to specs you cannot do that. Media queries are different than properties values that can changes with cascade. @tabatkins gave me a pretty good explanation once, cannot remember completely nor find it :/

from postcss-custom-media.

tabatkins avatar tabatkins commented on July 23, 2024

Right. "Variables" are just custom properties. Properties apply to elements, and the var() function takes the value of the corresponding property on the element and substitutes it in.

@media isn't an element, and so doesn't have any property to take from.

from postcss-custom-media.

VinSpee avatar VinSpee commented on July 23, 2024

interesting and understood. Any thoughts on ways to manage custom media values? I'm using a modular scale for sizing, and it essentially gives a list of sizes in em. Do I really have to manually put in the value? Feels archaic :-)

from postcss-custom-media.

VinSpee avatar VinSpee commented on July 23, 2024

Looks like I could use something like postcss-simple-vars to do the trick. Thanks and sorry for the false alarm!

from postcss-custom-media.

tabatkins avatar tabatkins commented on July 23, 2024

Note as well that the CSSWG is developing custom media queries http://dev.w3.org/csswg/mediaqueries/#custom-mq which'll help you out natively.

from postcss-custom-media.

VinSpee avatar VinSpee commented on July 23, 2024

@tabatkins not really - as far as I understand it, I will have to supply the actual value to the custom media query when I'm creating it, so I couldn't do something like:

:root {
  --ms6: 4.5em;
}

@custom-media --palm (min-width: var(--ms6));

@media (--palm) {
  html {
    color: red !important;
  }
}

from postcss-custom-media.

tabatkins avatar tabatkins commented on July 23, 2024

Yes, you have to put the value into the MQ. If you're using the value in both Variables and MQs, you'll have to repeat it. CSS is unlikely to sprout macros that allow you to substitute values into arbitrary contexts.

from postcss-custom-media.

VinSpee avatar VinSpee commented on July 23, 2024

@MoOx looks like it doesn't even work with postcss-simple-vars:

INPUT:

@custom-media --palm (min-width: $palm);
@media (--palm) {
    html {
         background: red !important;
    }
  }

OUTPUT:

@media (min-width: $palm) {
    html {
         background: red !important;
    }
  }

from postcss-custom-media.

ai avatar ai commented on July 23, 2024

@VinSpee very strange, because simple vars should support variables in custom at-rules.

What is your plugins order? Can you show me how you define $palm?

from postcss-custom-media.

MoOx avatar MoOx commented on July 23, 2024

@ai node.params.indexOf('$(') you look for $(.

postcss-custom-media is doing his job here so I am closing this issue.

from postcss-custom-media.

ai avatar ai commented on July 23, 2024

@MoOx nope, I call bothSyntax function for params. But you are right, it is relevant to simple-vars.\

@VinSpee please open issue here https://github.com/postcss/postcss-simple-vars/issues/new

from postcss-custom-media.

VinSpee avatar VinSpee commented on July 23, 2024

I opened postcss/postcss-simple-vars#3 which is causing this issue. Thanks all

from postcss-custom-media.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.