Skip to content

Commit

Permalink
Add note about min-/max- shortcoming vs proper range context
Browse files Browse the repository at this point in the history
Closes #984
Additionally, wraps `<div class="note">` around the note in range
context prose.
  • Loading branch information
patrickhlauke committed Mar 7, 2017
1 parent 1b4f7f4 commit d2dae8c
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions mediaqueries/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,11 @@ Evaluating Media Features in a Range Context</h4>
T: )
</pre>

Note: This syntax is new to Level 4 of Mediaqueries,
and thus is not as widely supported at the moment
as the ''min-''/''max-'' prefixes.
<div class="note">
Note: This syntax is new to Level 4 of Mediaqueries,
and thus is not as widely supported at the moment
as the ''min-''/''max-'' prefixes.
</div>

The basic form,
consisting of a feature name,
Expand Down Expand Up @@ -634,6 +636,34 @@ Using “min-” and “max-” Prefixes On Range Features</h4>
For example, ''(max-width: 40em)'' is equivalent to ''(width <= 40em)''.
</ul>

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

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

0 comments on commit d2dae8c

Please sign in to comment.