HTML and CSS Reference
In-Depth Information
JavaScript. We can use the HTML5 shiv script to do just that, but we really only need to send that script to
IE and not to any other browsers.
We first mentioned the HTML5 shiv back in Chapter 4, and you can read more about its
history—including why they called it a “shiv” when it should be a “shim”—in Paul Irish's
blog post, “The Story of the HTML5 Shiv” (
the-html5-shiv/ ). Download the script at
Conditional Comments for Internet Explorer
Conditional comments are a proprietary browser feature—first introduced with Internet Explorer 5 for
Windows in 1999—that allow developers to delineate blocks of HTML that will only be visible in certain
browsers. They're not a standard feature and haven't been implemented by any other browser besides IE,
but conditional comments are a relatively foolproof way to deliver content to IE while hiding it from other
browsers (or to hide content from IE while showing it to all others).
A conditional comment looks something like this:
<!--[if IE]>
Only Internet Explorer can see this text.
This special comment is conditional because it's structured as a logical argument, applying only if the
browser meets the specified conditions. The argument above simply states, “if the user-agent is Internet
Explorer, process the contents of this comment.” All other browsers—even any non-IE browsers that might
support conditional comments—will treat the entire thing as a normal HTML comment in and won't parse
or render it.
You can target specific versions of IE by extending the condition with the version number: [if IE 7] .
There are other logical operations as well, targeting versions less than, greater than, or equal to the stated
version. The basic argument operators are:
[if IE] - all versions of Internet Explorer for Windows
[if IE X] - only version X (where X is a version number)
[if lt IE X] - versions less than (but not equal to) X
[if lte IE X] - versions less than or equal to X
[if gt IE X] - versions greater than (but not equal to) X
[if gte IE X] - versions greater than or equal to X
There are a few additional operators to produce more complex expressions, but these are the basics.
Regardless, only Internet Explorer can interpret these comments; every other browser in the world ignores
them entirely. You can learn more about conditional comments and some of the ways you can use them in
Sitepoint's CSS reference ( .
Search WWH ::

Custom Search