Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position of nested media query can cause invalid CSS #602

Closed
brycewray opened this issue Aug 30, 2023 · 3 comments
Closed

Position of nested media query can cause invalid CSS #602

brycewray opened this issue Aug 30, 2023 · 3 comments

Comments

@brycewray
Copy link

I am using Hugo 0.117.0, one dependency of which is v2.12.7 of minify. While locally testing the relatively new CSS nesting standard (now supported by the current versions of Chrome, Firefox, and Safari), I have observed that the inclusion of a nested @media query causes minify to eliminate the required whitespace surrounding the + and - operators within a clamp() statement if the statement follows the media query within the same class or element. (I couldn't reproduce the same problem with calc().)

Examples

This CSS doesn't have the problem:

.myClass {
  & h1 {
    font-size: clamp(2.5rem, 1rem + 3vw, 3.5rem);
  }
  @media screen and (min-width: 1024px) {
    width: 40%;
  }
}

As of now, minify turns the first CSS into:

.myClass{& h1 { font-size: clamp(2.5rem, 1rem + 3vw, 3.5rem); } @media screen and (min-width: 1024px) { width: 40%; }};

But this CSS does have the problem:

.myClass {
  @media screen and (min-width: 1024px) {
    width: 40%;
  }
  & h1 {
    font-size: clamp(2.5rem, 1rem + 3vw, 3.5rem);
  }
}

As of now, minify turns the second CSS into:

.myClass{@media screen and (min-width:1024px){width: 40%; } & h1 { font-size: clamp(2.5rem,1rem+3vw,3.5rem); } }}}

cc: @bep @jmooring

@tdewolff
Copy link
Owner

tdewolff commented Sep 4, 2023

Thanks for the issue. The CSS minifier does not support this syntax yet, but now it handles the "error" better. This should be fixed now!

@brycewray
Copy link
Author

Thanks for the issue. The CSS minifier does not support this syntax yet, but now it handles the "error" better. This should be fixed now!

@tdewolff Thanks! Which version of minify?

@tdewolff
Copy link
Owner

tdewolff commented Sep 4, 2023

I've just released v2.12.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants