W3C home > Mailing lists > Public > whatwg@whatwg.org > November 2013

Re: [whatwg] <imgset> responsive imgs proposition (Re: The src-N proposal)

From: Markus Lanthaler <markus.lanthaler@gmx.net>
Date: Tue, 12 Nov 2013 17:48:07 +0100
To: "'Markus Ernst'" <derernst@gmx.ch>, "'Ryosuke Niwa'" <rniwa@apple.com>
Message-ID: <01f701cedfc6$f8030830$e8091890$@lanthaler@gmx.net>
Cc: "'Jukka K. Korpela'" <jkorpela@cs.tut.fi>, 'whatwg' <whatwg@lists.whatwg.org>, 'Adam Barth' <w3c@adambarth.com>
On Tuesday, November 12, 2013 5:04 PM, Markus Ernst wrote:
> > We could define some ways to list set of images that could be
> replaced for a given img element in HTML and then let CSS pick which
> one to use for example.
> 
> <style type="text/css">
> @media (min-width: 480px) {
>    img.artdirected {
>      use-src: 1;
>    }
> }
> @media (min-width: 600px) {
>    img.artdirected {
>      use-src: 2;
>    }
> }
> </style>
> 
> <img class="artdirected"
>       src="small.jpg"
>       src-1="medium.jpg"
>       src-2="large.jpg"
>       alt="Alternative text">
> 
> [...]
> 
> This may be technically incorrect or incomplete; it's just a sketch of
> the idea, based on my conviction that sources belong into the <img>
> element, while MQs should be kept centralised.

Using URL templates this could be simplified even further. For example by
extending the meta element to allow it to set some form of global
configuration variables it would be possible to define images using a simple
naming convention:

<head>
  <meta var="img-size" content="small">
  <meta var="img-size" content="medium" media="min-width: 480px">
  <meta var="img-size" content="large" media="min-width: 900px">
</head>
<body>
  <img src="teaser-fallback.jpg" src-t="teaser-{img-size}.jpg">
  <img src="profile-fallback.jpg" src-t="profile-{img-size}.jpg">
</body>

If a variable is set multiple times as in the case above, the latest
assignment wins. As soon as the closing head tag is encountered, the value
of all variables is known and they effectively become constants that can be
used to fill the URL templates of the images in the document's body.


--
Markus Lanthaler
@markuslanthaler
Received on Tuesday, 12 November 2013 16:48:40 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:14 UTC