To answer the original question, IE8 does not support the canvas
element. Modernizr will add the canvas
class to the <html>
tag for modern browsers, and alternatively, it will add the no-canvas
class for IE8 and below. Therefore, you could do this to target modern browsers:
.canvas .my-checkbox-style { /* CSS for modern browsers, but not IE8 or lower */ }
Alternatively, you could do this to target IE8 and lower:
.no-canvas .my-checkbox-style { /* CSS for IE8 or lower */ }
However, there are a couple of things worth further mention here...
Browsers will not honor CSS selectors and properties they do not support.
If the intention is to truly hide your modern browser CSS from IE8 entirely, you need to serve up separate stylesheets altogether via conditional statements, like this:
<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->
<!--[if gt IE 8]>
<link rel="stylesheet" type="text/css" href="ie9-and-up.css" />
<![endif]-->
<!--[if !IE]><!-->
<link rel="stylesheet" type="text/css" href="non-ie-browsers.css" />
<!--<![endif]-->
Architecturally speaking, presuming modern browsers are the 'first class citizens' in your styling objectives, your stylesheets should be written from their modern perspective as a norm. This will make your overall development process easier, as well as uncluttered with classes that unnecessarily target 'modern' browsers. Target IE8 and below with the no-canvas
class, and over-ride the modern browser CSS therein, to return the IE8 checkboxes to their default state. You can then easily prune this self-contained over-ride from your CSS codebase when the time comes to drop IE8 support.
I've written a Codepen example to illustrate the use of canvas
and no-canvas
.