Return to parent article on media queries
Simple image tag that will show up when page is greater than 500 pixels wide, but are hidden on smaller screens.
<div id="imgtest">
<img src="test1.png" />
</div>
<style type="text/css">
@media all and (max-width: 500px) {
#test1 {
display:none;
}
}
</style>
iPhone doesn't display images, but images are still downloaded.
Two divs are assigned background images. These divs are hidden when the page is smaller than 500 pixels.
<div id="test2"></div>
<style type="text/css">
#test2 {background-image:url('test2.png');width:200px;height:75px;}
@media all and (max-width: 500px) {
#test2 {display:none;}
}
</style>
iPhone doesn't display images, but images are still downloaded.
This should be no different than test #2, but I observed some strange behavior on the dConstruct site that makes me think this might work where #2 does not.
<div id="test3">
<div></div>
</div>
<style type="text/css">
#test3 div {background-image:url('test3.png');width:200px;height:75px;}
@media all and (max-width: 500px) {
#test3 {display:none;}
}
</style>
Works! iPhone doesn't display image. Doesn't download image.
In this test, we start with a css background image that is a desktop version of the image. Then we use a css media query to replace that background image with a mobile version of the image.
<div id="test4"></div>
<style type="text/css">
#test4 {background-image:url('test4-desktop.png');width:200px;height:75px;}
@media all and (max-width: 500px) {
#test4 {background-image:url('test4-mobile.png');}
}
</style>
iPhone doesn't display desktop image, but downloads both desktop and mobile images.
In this test, I'm trying to isolate the desktop image by using min-width declaration in addition to the max-width for the mobile image.
<div id="test5"></div>
<style type="text/css">
@media all and (min-width: 501px) {
#test5 {background-image:url('test5-desktop.png');width:200px;height:75px;}
}
@media all and (max-width: 500px) {
#test5 {background-image:url('test5-mobile.png');width:200px;height:75px;}
}
</style>
Works! iPhone doesn't display desktop image. Doesn't download desktop image.