garden icon indicating copy to clipboard operation
garden copied to clipboard

Incorrect CSS emitted for inner media queries

Open vemv opened this issue 6 years ago • 6 comments

The Sass compiler supports "inner media queries" (for lack of a better name, that I know of):

image

I'm failing to replicate that feature with Garden.

This is my attempt:

[:img {:max-width "424px"}
   (at-media {:max-width (u/px 700)}
     {:max-width "100%"})]

But the output is incorrect:

img {
  max-width: 424px;
}

@media (max-width: 700px) {

  max-width: 100%;

}

...In the emitted CSS, the media query lacks the img qualifier.

The following works:

  [[:img {:max-width "424px"}]
   (at-media {:max-width (u/px 700)}
     [:img
      {:max-width "100%"}])]

...but that breaks DRY: the img selector is repeated. In real-world usage the selector may be more complex, with a higher cost for repetition.

Also for bigger stylesheets I find this construction a bit confusing. At least coming from Sass, I see the Sass-style nesting more intuitive.

WDYT?

Thanks - Victor

vemv avatar Feb 04 '19 22:02 vemv

I took a quick peek into it and it seems like it should be possible but I'd need to spend a little time investigating it.

noprompt avatar Feb 04 '19 23:02 noprompt

Nice!

vemv avatar Feb 04 '19 23:02 vemv

@vemv I haven't had a chance to really get into this yet. Apologies.

noprompt avatar Feb 15 '19 16:02 noprompt

No issue 🙌

vemv avatar Feb 16 '19 06:02 vemv

Instead of modifying the CSS generator, I suggest to solve the problem via a function pull-media-query-to-the-root which take a garden data as input and return a garden data as output.

green-coder avatar Feb 02 '21 04:02 green-coder

@green-coder can you submit a patch?

noprompt avatar Feb 02 '21 05:02 noprompt