Skip to content

Instantly share code, notes, and snippets.

@sergejmueller
Created December 8, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergejmueller/2452451e583b3e33cce58cfa3255c94c to your computer and use it in GitHub Desktop.
Save sergejmueller/2452451e583b3e33cce58cfa3255c94c to your computer and use it in GitHub Desktop.
Media Queries with dynamically image loading
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Your Message Subject or Title</title>
<style type="text/css">
.bg {
width:300px;
height:200px;
display: block;
}
@media all and (max-width: 600px) {
.bg {
background-image: url('https://dummyimage.com/300x200/000/fff&text=Mobile');
}
}
@media all and (min-width: 601px) {
.bg {
background-image: url('https://dummyimage.com/300x200/000/fff&text=Desktop');
}
}
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td class="bg">
<!--[if gte mso 9]>
<img src="https://dummyimage.com/300x200/000/fff&text=Desktop" width="300" height="200" style="display:block" />
<![endif]-->
</td></tr>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment