whats wrong with the media query?

2019-09-09 07:07发布

问题:

W3C standards doc says:

User agents are to represent a media query as "not all" when one of the specified media features is not known.

Then it gives following example:

<link rel="stylesheet" media="screen and (max-weight: 3kg) and (color), (color)" href="example.css" />

It then says that the first media query will be represented as "not all" and evaluate to false and the second media query is evaluated as if the first had not been specified, effectively.

Why is it like that. I hope that's because 3kg value for max-weight is not the valid value, which is not explained in doc as a reason. However I cant see any unknown media-feature but "Unknown media feature value", which is discussed separately in the document just after "Unknown media features". I think this example should have been put below "Unknown media feature value" but not in "Unknown media features".

回答1:

The unknown media feature that the example is referring to is max-weight. Once that is encountered, the 3kg value is no longer relevant since it will never be applicable anyway, because the browser won't know what to do with max-weight in the first place. So it skips that media query altogether, leaving you effectively with this:

<link rel="stylesheet" media="not all, (color)" href="example.css" />

Which is the same as this:

<link rel="stylesheet" media="(color)" href="example.css" />

Media features are described in another section. The first sentence states:

Syntactically, media features resemble CSS properties: they have names and accept certain values.

So it only makes sense to describe error handling of the media features themselves first, then handling of their values.