elm-css icon indicating copy to clipboard operation
elm-css copied to clipboard

Multiple media queries do not cascade

Open glitteringkatie opened this issue 6 years ago • 3 comments

We have the following two media queries and expect them to apply in a cascading way.

[ Css.Media.withMedia
    [ only screen
        [ minWidth (px 1)
        , maxWidth (px 800)
        ]
    ]
    [ Css.width (Css.pct 32)
     , Css.height (Css.px 100)
    ]
, Css.Media.withMedia
    [ only screen
        [ minWidth (px 1)
        , maxWidth (px 376)
        ]
    ]
    [ Css.width (Css.pct 48)
    , Css.height (Css.px 100)
    ]
]

Instead, once the smaller size is hit, the 800 styles override the 376 styles. image

glitteringkatie avatar Feb 22 '19 00:02 glitteringkatie

It's been awhile since I spent time in the media queries portion of this code base, but as I recall, there are some unfortunate design constraints elsewhere which make it impossible for this to work as expected.

I believe the solution is to change the top one from minWidth (px 1) to minWidth (px 377). Let me know if that works!

rtfeldman avatar Feb 22 '19 02:02 rtfeldman

👍 Thanks for getting back to us and bummer about the design constraints. The suggestion does seem to work, so thanks you!

brookeangel avatar Feb 22 '19 23:02 brookeangel

Having the same issues. Here it works defining them in the opposite order in elm-css of what you normally would do with css media queries, then the style tag comes out with them correct.

For instance, if I define mediaQueryA and mediaQueryB in that order in elm-css, the <style>-tag it outputs contains them in the reverse order, so mediaQueryB above mediaQueryA.

This may be arbitrary, but at least it works in my case here. Just a tad annoying having to do it the opposite way of what I do when writing css. Not sure if we can depend on that order, though?

Matsemann avatar Mar 15 '19 11:03 Matsemann