Skip to content

Commit 6abf748

Browse files
committed
Add note about min-/max- shortcoming vs proper range context
Closes #984
1 parent 1b4f7f4 commit 6abf748

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

mediaqueries/Overview.bs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,34 @@ Using “min-” and “max-” Prefixes On Range Features</h4>
634634
For example, ''(max-width: 40em)'' is equivalent to ''(width <= 40em)''.
635635
</ul>
636636

637+
Note: because “min-” and “max-” both equate to range comparisons that <strong>include</strong> the value,
638+
they may be limiting in certain situations.
639+
640+
<div class='example'>
641+
For instance,
642+
authors trying to define different styles based on a breakpoint in the viewport width using “min-” and “max-”
643+
would generally offset the values they're comparing,
644+
to ensure that both queries don't evaluate to true simultaneously.
645+
Assuming the breakpoint is at 320px, authors would conceptually use:
646+
647+
<pre>
648+
@media (max-width: 320px) { /* styles for viewports <= 320px */ }
649+
@media (min-width: 321px) { /* styles for viewports >= 321px */ }
650+
</pre>
651+
652+
While this ensures that the two sets of styles don't apply simultaneously when the viewport width is 320px,
653+
it does not take into account the possibility of fractional viewport sizes which can occur as a result of non-integer pixel densities
654+
(e.g. on high-dpi displays or as a result of zooming/scaling).
655+
Any viewport widths that fall between 320px and 321px will result in none of the styles being applied.
656+
657+
In these situations, <a>range context</a> queries (which are not limited to “>=” and “<=” comparisons) offer a more appropriate solution:
658+
659+
<pre>
660+
@media (width <= 320px) { /* styles for viewports <= 320px */ }
661+
@media (width > 320px) { /* styles for viewports > 320px */ }
662+
</pre>
663+
</div>
664+
637665
“Discrete” type properties do not accept “min-” or “max-” prefixes.
638666
Adding such a prefix to a “discrete” type <a>media feature</a> simply results in an unknown feature name.
639667

0 commit comments

Comments
 (0)