Mobile devices
A number of people are using small mobile devices to read Web pages. These devices have small screens, which make it hard to read pages designed for a large screen width.
CSS Media types to the rescue
Good news: the W3C thought of that fourteen years ago, when they introduced the concept of media types in CSS 2:
<link rel="stylesheet" type="text/css" media="handheld"/>
Here, the attribute media="handheld"
indicates this dedicated style sheet
should be loaded by “hand-held devices (typically small screen, limited
bandwidth)” (quoting the CSS 2.1 Specification). Cool stuff, for a
specification written in 1998, is it not?
… or not
Well, bad news: mobile browsers do not honour it. Try this test page with a hand-held device: if the browser respects the specification, it should display a section of text which is not shown for regular browsers. It probably wont.
So, how do people do to implement a specific style for mobile devices? Well, the W3C seemed to acknowledge the fact that mobile browser authors had no intention of respecting the existing specification, so they extended it with Media Queries:
<link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)"/>
Here, this attribute indicates this dedicated style sheet is to be loaded by devices with a screen not too large (in pixels: not sure how this would work with small but high resolution screens). Thank you, mobile browsers, for not implementing a specification that was designed just for you before you even existed, and requiring such a kludge with a new specification instead…
12 comments
friday 23 november 2012 à 13:01 Screwtape said : #1
friday 23 november 2012 à 13:49 Claudius said : #2
friday 23 november 2012 à 14:12 Riku Voipio said : #3
friday 23 november 2012 à 14:16 Tanguy said : #4
friday 23 november 2012 à 17:41 guy said : #5
friday 23 november 2012 à 19:17 niq said : #6
friday 23 november 2012 à 20:29 Emanuele Aina said : #7
friday 23 november 2012 à 20:30 Emanuele Aina said : #8
friday 23 november 2012 à 22:43 Tanguy said : #9
sunday 25 november 2012 à 01:59 MJ Ray said : #10
monday 26 november 2012 à 16:36 agence web said : #11
thursday 22 january 2015 à 22:53 Jens Oliver Meiert said : #12