Media Queries Daniel Glazman CSSDay.nl 14 June 2013 CSS WG What - - PowerPoint PPT Presentation

media queries
SMART_READER_LITE
LIVE PREVIEW

Media Queries Daniel Glazman CSSDay.nl 14 June 2013 CSS WG What - - PowerPoint PPT Presentation

Media Queries Daniel Glazman CSSDay.nl 14 June 2013 CSS WG What it is about... Select styles based on device's characteristics A large CSS-based part... and a little API-based part The main component of Responsive Design


slide-1
SLIDE 1

Media Queries

Daniel Glazman CSSDay.nl · 14 June 2013

slide-2
SLIDE 2

CSS WG

slide-3
SLIDE 3

What it is about...

Select styles based on device's characteristics The main component of « Responsive Design »

  • A large CSS-based part...
  • and a little API-based part
slide-4
SLIDE 4

History (CSS part)

  • Proposed as a WD by Opera and Microsoft

in April 2001

  • First CR in July 2002
  • PR in April 2012...
  • REC in June 2012...
  • Implemented by all modern browsers
slide-5
SLIDE 5

Original HTML4/CSS2 media types

all braille embossed handheld print projection screen speech tty tv

slide-6
SLIDE 6

HTML 4.01

6.13 Media descriptors Future versions of HTML may introduce new values and may allow parameterized values. Each entry is truncated just before the first character that isn’t a US ASCII letter [a-zA-Z] (ISO 10646 hex 41-5a, 61-7a), digit [0-9] (hex 30-39), or hyphen (hex 2d)

slide-7
SLIDE 7

CSS 2.1

@media screen { ... } <link rel="stylesheet" type="text/css" href="foo.css" media="screen" /> <style type="text/css" media="screen" />

slide-8
SLIDE 8

Media Queries

@media screen and (max-width: 500px) { ... } <link rel="stylesheet" type="text/css" href="foo.css" media="screen and (max-width: 500px)" /> <style type="text/css" media="screen and (max-width: 500px)" />

slide-9
SLIDE 9

Syntax

print screen AND (color) AND (min-width: 100px) NOT screen AND (max-width: 500px) projection, handheld AND (max-resolution: 92dpi) (orientation: portrait) ONLY screen AND (max-width: 500px)

false true true true false false

slide-10
SLIDE 10

CSS powaaaah

screen AND (max-width: calc(650px - 2em))

slide-11
SLIDE 11

NOT

NOT projection and (orientation: landscape)

true true true false NOT negates the whole query, not the media type only...

slide-12
SLIDE 12

ONLY

it's only here to hide style sheets from older user agents...

slide-13
SLIDE 13

Don't worry...

Groups of media descriptors are not dropped if one descriptor only is invalid

screen, projection, print AND (vendor: epson) screen, projection

slide-14
SLIDE 14

Media Features

width <length> height <length> device-width <length> device-height <length>

  • rientation

portrait | landscape aspect-ratio <integer>/<integer> device-aspect-ratio <integer>/<integer> color <integer> | ∅ color-index <integer> | ∅ monochrome <integer> | ∅ resolution <number>(dpi | dpcm) scan progressive | interlace grid <integer> | ∅

slide-15
SLIDE 15

The API part

media serialization of the query matches true if the current rendering matches the query addListener() removeListener() to listen to query changes

MediaQueryList window.matchMedia(query)

slide-16
SLIDE 16

What's missing #1

  • paginated browsing
  • ambient light detection
  • JavaScript's availability
  • human language
  • ...
slide-17
SLIDE 17

What's missing #2

CSSRule.matchingMedia

query necessary for that rule to be applied

CSSRule.matchMedia(query)

is the query enabing that CSS rule?

MediaList

parsed representation of each query

slide-18
SLIDE 18

Media Queries

  • n steroids
  • a Media Query is a condition
  • a condition is a boolean
  • trivial to write a JavaScript function

returning a boolean Conclusion ?-)

slide-19
SLIDE 19

Media Queries

  • n steroids #2

CSS.customMedia("foobar", CSSMFfoobar); CS.customMedia.update(aFeature, aValue);

slide-20
SLIDE 20

Media Queries

  • n steroids #3

CSSMFfoobar { get value() { ... }, resolve: function(aFeature, aPrefix, aValueString) { /* BOOL */ }, addListener: function(aEngine, aFeature) { /* adds device listener /* }, removeListener: function(aEngine, aFeature) { /* remove device listener /* }, }

slide-21
SLIDE 21

Maintenance

We should be able to associate a name to a given Media Query for readability and maintenance reasons.

@var iPadRetinaL screen AND (orientation: landscape) AND (resolution: 264dpi); @media var(tablet) { ... }

21

slide-22
SLIDE 22

Future of Media Types

  • we don't need screen, print or speech
  • we can move to media features !
slide-23
SLIDE 23

Thank you!

Questions? http://www.w3.org/TR/css3-mediaqueries/ http://www.w3.org/TR/cssom-view/ http://www.bluegriffon.org/ daniel@glazman.org @glazou