For some reason any Less I have written inside the @media-common = true media query does not load in IE9. I can't find any specific code to prevent this from rendering out in IE9.
It happens whether it's client-side Less compilation or deployed to a server in production mode with server side compilation.
I've tried clearing the usual directories, clearing caches, running the deploy static content command.
All the CSS updates and loads in IE9 minus any styling within the & when (@media-common = true) {} mixin.
Example
For example ther following code should render the background to be green as it has important, this works as expected in every browser and device except IE9.When I load the website in IE 9 the background is blue.
//
// Common
// _____________________________________________
& when (@media-common = true) {
body {
background-color: green !important;
}
}
//
// Mobile
// _____________________________________________
.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
body {
background-color: red;
}
}
//
// Tablet and above
// _____________________________________________
.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
body {
background-color: blue;
}
}
Question
Why is IE9 ignoring any code inside & when (@media-common = true) {}?
2 Answers 2
Magento 2 no longer supports IE9 so this is unlikely to ever be fixed by Magento
It's looking very likely that this is down to the fact IE9 can only support up to 4096 selectors, my styles-m.css currently has 4977 selectors (due to having Luma as a parent (bad idea!)).
The styles inside the media-common mixin aren't displaying as they are placed last, after the 4096 limit.
It seems my only solution is to split the CSS up into multiple files, this should be fun!
Update: - This was indeed down to the 4096 selector limit, adding my own CSS files instead of using styles-l.css and styles-m.css resolved it although it was a huge pain.
-
hi @Ben Crook, I included css file like below, <css src="css/ie_styles.css" ie_condition="IE" /> can this load only IE?Jafar Pinjar– Jafar Pinjar2019年07月17日 15:16:48 +00:00Commented Jul 17, 2019 at 15:16
Try changing the order of your styles so that you do not need to add !important. If you move
& when (@media-common = true) { body { background-color: green; } }
to be the last item instead of the first, the nature of cascading stylesheets means this will cascade down and use the last style specified that is relevant.
-
The problem isn't the specificity, the problem is that any CSS inside the @media-common = true mixin does not load in IE9. I have only added important to show that the background should be green, but it isn't (it's blue). Moving CSS has no impact on this.Ben Crook– Ben Crook2016年06月20日 08:53:48 +00:00Commented Jun 20, 2016 at 8:53
-
Turns out it's because IE9 can only handle 4096 selectors, my theme has 4977.Ben Crook– Ben Crook2016年06月20日 09:16:23 +00:00Commented Jun 20, 2016 at 9:16
Explore related questions
See similar questions with these tags.
pub/static/frontend/{{vendor}}/{{theme}}/en_US/css/styles-m.csssheet. you are saying that those styles are not in this sheet in ie9?