File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments