I am using Modernizr v3 on my website to test for flexbox support.
Modernizr adds a "flexbox"
body class for browsers that support it, and "no-flexbox"
for browsers that do not. As browsers that don't support flexbox are only a minority of my audience, I have used the "no-flexbox"
class to provide fall back CSS. For example:
.ad { /* Default CSS */
display: flex;
}
.no-flexbox .ad { /* Fallback CSS*/
display:table;
}
Everything works fine, except for IE10, as Modernizr adds a "no-flexbox" class to it, even though IE10 does support Flexbox, it is just using the older syntax. Therefore, on IE10 my layout is broken as it reads both the flex box and non-flexbox styles.
In this thread, it says that moderniser has a flexboxtweener style to IE10. Therefore, I thought I could rewrite my fall backs to use .no-flexboxtweaner
instead of .no-flexbox
.
The problem is that browsers that support the new flexbox syntax get given a no-flexboxtweaner class as well, so they read the fallback code.
How can I set it up so that only the browsers that do not support any form flexbox (regardless if it is new or old) get the "no" class.
I know I could do ".no-flexbox .ad, .no-flexboxtweaner .ad", but then that's bloating the CSS (plus running two Modernizr tests). I'd rather just have a single test/class.
Thats kindof silly, mate. It is a handful of bytes - almost all of which will be erased by gzipping your file. If you reallllly wanted to avoid it, you could create an additional Modernizr check that gives you any flexbox
that will create a new property called
anyflexbox
and you can style your css accordingly.