Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mediaqueries-4] Add note about min-/max- shortcoming vs proper range context #1083

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mediaqueries/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,34 @@ Using “min-” and “max-” Prefixes On Range Features</h4>
For example, ''(max-width: 40em)'' is equivalent to ''(width <= 40em)''.
</ul>

Note: because “min-” and “max-” both equate to range comparisons that <strong>include</strong> the value,
they may be limiting in certain situations.

<div class='example'>
For instance,
authors trying to define different styles based on a breakpoint in the viewport width using “min-” and “max-”
would generally offset the values they're comparing,
to ensure that both queries don't evaluate to true simultaneously.
Assuming the breakpoint is at 320px, authors would conceptually use:

<pre>
@media (max-width: 320px) { /* styles for viewports <= 320px */ }
@media (min-width: 321px) { /* styles for viewports >= 321px */ }
</pre>

While this ensures that the two sets of styles don't apply simultaneously when the viewport width is 320px,
it does not take into account the possibility of fractional viewport sizes which can occur as a result of non-integer pixel densities
(e.g. on high-dpi displays or as a result of zooming/scaling).
Any viewport widths that fall between 320px and 321px will result in none of the styles being applied.

In these situations, <a>range context</a> queries (which are not limited to “>=” and “<=” comparisons) offer a more appropriate solution:

<pre>
@media (width <= 320px) { /* styles for viewports <= 320px */ }
@media (width > 320px) { /* styles for viewports > 320px */ }
</pre>
</div>

“Discrete” type properties do not accept “min-” or “max-” prefixes.
Adding such a prefix to a “discrete” type <a>media feature</a> simply results in an unknown feature name.

Expand Down