Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 & CSS - media queries operators question

I was wondering if someone can explain what each of the media queries in the example below mean in simple terms?

Here is the examples.

media="not screen and (color)" 
media="projection, screen and (color)" 
media="only projection and (color)"
like image 288
HELP Avatar asked Apr 22 '11 21:04

HELP


People also ask

What HTML5 is used for?

HTML5 allows you to build offline applications. Browsers that support HTML5 offline applications (which is most) will download the HTML, CSS, JavaScript, images, and other resources that make up the application and cache them locally.

What is HTML5 vs HTML?

Hypertext Markup Language (HTML) is the primary language for developing web pages. HTML5 is a new version of HTML with new functionalities with markup language with Internet technologies. HTML does not have support for video and audio but, HTML5 supports both video and audio.

Is HTML5 still in use?

HTML5 is several years old now, and as the living standard of the language as a whole, it will only continue to get updated to work with the modern web.

What is HTML5 example?

The term HTML5 means not only HTML, it is a combination of HTML, CSS and Javascript with APIs . For example, drawing and animation using canvas, offline storage, microdata, audio and video, drag and drop, geolocation, embedded fonts, web APIs etc.


1 Answers

To analyze what media queries mean, you basically need to keep these things in mind:

  1. A comma means "or".
  2. The unparenthesized thing at the beginning of a media query is the name of the medium the query is for (unless that word is "not" or "only", in which case the second word is the medium involved.
  3. "not" negates everything up to the comma that follows.
  4. Things in parens are modifiers.
  5. The algorithm HTML4 specified for parsing media is horribly broken: it just extracts the first word from each part between commas. The keyword 'only' was introduced to allow media query authors to work around this bug. A UA that implements media queries just ignores this keyword.

So now in order.

Your first media query selects everything that's not a "screen and (color)". So it selects anything that's not a color screen (i.e. non-screens and also monochrome screens).

Your second media query selects anything that's a projection medium (whether color or monochrome) or a color screen.

Your third media query selects color projection media in UAs that implement media queries. In a UA that implements the HTML 4 algorithm, it's ignored because "only" is not an HTML 4 media specifier. If "only" were left out, then in old UAs it would select all projection media, because it would just extract that first word and ignore the "and (color)" part.

like image 124
Boris Zbarsky Avatar answered Oct 07 '22 01:10

Boris Zbarsky