Skip to content

Instantly share code, notes, and snippets.

@keithchu
Created September 7, 2012 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keithchu/3664309 to your computer and use it in GitHub Desktop.
Save keithchu/3664309 to your computer and use it in GitHub Desktop.
image-set() & srcset demo
<article class="sandbox">
<header>
<h1>Demo of <code>image-set()</code> and <code>srcset</code></h1>
</header>
<section class="image-set">
<h2><code>image-set()</code></h2>
<!-- 1. normal use case, bg images -->
<i class="image-set-one"></i>
<!-- 2. image "element" -->
<i class="image-set-two" style="content: url('http://cl.ly/JGCU/icon1x.png'); content: -webkit-image-set(url('http://cl.ly/JGCU/icon1x.png') 1x, url('http://cl.ly/JFp6/icon2x.png') 2x);"></i>
</section>
<section class="srcset">
<h2><code>srcset</code></h2>
<!-- no browser support yet -->
<img alt="srcset icon" src="http://cl.ly/JGCU/icon1x.png" srcset="http://cl.ly/JFp6/icon2x.png 2x, http://cl.ly/JFp6/icon2x-hd.png 2x 640w" />
</section>
<footer>
<ol>
<li><sup>1</sup> <a href="http://www.html5rocks.com/en/mobile/high-dpi/">High DPI Images for Variable Pixel Densities</a> by @smus</li>
<li><sup>2</sup> <a href="http://blog.cloudfour.com/safari-6-and-chrome-21-add-image-set-to-support-retina-images/">Safari 6 and Chrome 21 add image-set to support retina images</a> by @cloudfour</li>
<li><sup>3</sup> <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html#attr-img-srcset">whatwg: srcset</a></li>
</ol>
</footer>
</article>
@import "compass"
.image-set-one
background-image: url('http://cl.ly/JGCU/icon1x.png')
background-image: -webkit-image-set(url('http://cl.ly/JGCU/icon1x.png') 1x, url('http://cl.ly/JFp6/icon2x.png') 2x)
display: inline-block
height: 128px
margin-right: 3em
width: 128px
vertical-align: middle
.image-set-two
display: inline-block
height: 128px
width: 128px
vertical-align: middle
@keithchu
Copy link
Author

keithchu commented Sep 7, 2012

Rendered (on Codepen): http://codepen.io/keithchu/pen/nFmlb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment