25
loading...
This website collects cookies to deliver better user experience
max-width
and min-width
media queries. I noticed that, while resizing the browser window, there was a brief moment where the layout was totally messed-up.#max200, #min201 {
display: none;
}
@media screen and (max-width: 200px) {
#max200 {
display: block;
}
}
@media screen and (min-width: 201px) {
#min201 {
display: block;
}
}
#max200
nor the #min201
element4.@media screen and (max-width: 200.999px)
for the first query but this will result in an overlap where both elements are shown on all browsers. It seems when parsing the media query, all browsers agree an rounding, treating max-width: 200.999px
the same as max-width: 201px
5.min-width-exclusive
and max-width-exclusive
construct?min-width
or max-width
queries but never mix them?As with most interesting conundrums, it plays out mostly in the fringes; this one more literally than others. ↩
And, as it increasingly seems to me, one of the few who doesn’t just care about getting things to work but getting them to work on grounds of principle as opposed to accident. ↩
Try it on my test page. ↩
Interestingly, on 5x zoom level, Chrome also briefly hides both elements. I attribute this to rounding errors. Safari doesn’t but it also zooms to max 3x so maybe the rounding problems don’t manifest. ↩
Also, it would be ugly even if it worked, as it relies on the fact that browsers don’t have infinite zoom capability (and users don’t have infinite desires for zooming in). ↩