-
-
Save anthonyshort/979912 to your computer and use it in GitHub Desktop.
Idea for CSS-only responsive images using CSS3 generated content and attr() function. No browser implementation as of May 2011
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>CSS responsive images</title> | |
<style> | |
/* Play nice with existing requirements for | |
Responsive Images polyfill */ | |
/* Doesn't stop original source image being | |
downloaded too */ | |
@media (min-device-width:600px) { | |
img[src*=".r."] { | |
content: attr(data-src-600px, url); | |
} | |
} | |
@media (min-device-width:800px) { | |
img[src*=".r."] { | |
content: attr(data-src-800px, url); | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<img src="image.r.jpg" | |
data-src-600px="image-600px.jpg" | |
data-src-800px="image-800px.jpg" | |
alt=""> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>CSS responsive images</title> | |
<style> | |
/* Doesn't stop original source image being | |
downloaded too */ | |
@media (min-device-width:600px) { | |
img[data-src-600px] { | |
content: attr(data-src-600px, url); | |
} | |
} | |
@media (min-device-width:800px) { | |
img[data-src-800px] { | |
content: attr(data-src-800px, url); | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<img src="image.jpg" | |
data-src-600px="image-600px.jpg" | |
data-src-800px="image-800px.jpg" | |
alt=""> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment