I was both surprised and delighted to see my css (i.e. class ralphBackground) applied to a an image in the following "art direction" code in Chrome (70.0.3538.77), Firefox (63.0.1), and Internet Explorer (11.0.9600.19155)
<style type="text/css">
.ralphBackground {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
width: 100%;
height: 100%;
transition: opacity 5.5s;
}
.ralphFadeIn {
opacity: 0;
transition: opacity 5.5s;
}
</style>
<div>
<picture>
<source srcset="/assets/root/360x740-text/740x360-text.png" media="(orientation: landscape)">
<source srcset="/assets/root/360x740-text/360x740-text.png" media="(orientation: portrait)">
<img class="ralphBackground" id="ralphBackgroundId" src="/assets/root/SomePicture - 2048x1367.png" />
</picture>
</div>
<div>
<script language="JavaScript" type="text/javascript">
const ralphBackground = document.getElementById('ralphBackgroundId');
$( window ).on('load', function() {
ralphBackground.style.opacity = '0.55';
});
</script>
</div>
In Chrome and Firefox, the css class ralphBackground is applied to the images 360x740-text.png or 740x360-text.png depending on the orientation (i.e. size) of the window and the appropriate image is displayed. This behavior both surprised and delighted me because I found no documentation anywhere saying this would happen.
In Explorer, it is the SomePicture - 2048x1367.png image which is displayed.
I quote the following from https://www.diffuse.nl/blog/creating-responsive-images-with-srcset-and-sizes :
You can see the src attribute is still mandatory. This is a fallback for a browser that doesn't support srcset and sizes. I guess you're not surprised this browser turns out to be Internet Explorer.
So my questions are:
1) Is the behavior I want (the application of css to the relevant image) undocumented behavior that is likely to change? Or is it documented somewhere and I just haven't found the documentation?
2) Is there some way to bully Explorer into behaving as I wish?
3) Does Explorer support media queries in a srcset?