I have the following media queries in my CSS:
@media screen and (min-width: 0px) and (max-width: 319px) {
body {background-color:red;}
}
@media screen and (min-width: 320px) and (max-width: 480px) {
body {background-color:orange;}
}
@media screen and (min-width: 481px) and (max-width: 980px) {
body {background-color:yellow;}
}
@media screen and (min-width: 981px) and (max-width: 1200px) {
body {background-color:green;}
}
@media screen and (min-width: 1201px) {
body {background-color:blue;}
}
and five iframes at corresponding sizes:
<iframe frameBorder="0" src="index.html" height="320" width="255" ></iframe>
The queries kick-in fine in the standalone html file, but when viewed in an iframe context, they fail in IE9. All other browsers display OK.
Anyone know why? thanks
[edit] For the record, the parent and child html have the same docType, and the CSS is being served as text/css.
Had the same Probleme. However I found an easy fix. Using JS to create the iframes I just appended something like ?nocache=Math.random() to the iframe src. That fixed it for me :)
I had this problem with IE9. The parent page didn't have a doctype declared.
Adding an html5 doctype (
<!DOCTYPE html>
) in the parent page solved the problem.Not a real answer but could help somebody else find a work around for this bug in IE.
Page containing iframes
Iframe pages
The param frameX prevents IE from caching the css page and thus the iframe has responsive layout independently from the other pages. This is just a hack(horrible one) and to help somebody else find the answer to this problem.
Sample files
Index.html
frame1.html
frame2.html
frame3.html
style.css
You most likely aren't going to be able to fix this. Media Queries are based on viewport size and I imagine IE isn't treating the iFrame as a fully fledged viewport in this context.
Your best bet would most likely be to add a bit of JavaScript that detects the size and adds a class to the at the same thresholds you are using for your responsive design. This would also give you backwards compatibility with browsers that don't support media queries.
Here's what I did:
Here's the code: