HTML and CSS Reference
In-Depth Information
These hacks are also not readable and without comments it is impossible to under-
stand which browsers they target.
The advantage of these methods is that you can keep your style rules together, and
you do not have to serve a separate stylesheet for the browsers requiring hacks.
Server-side browser detection
When they make a request to a web server, browsers send a User Agent String
along with the request. Servers can serve different resources based on their inter-
pretation of the User Agent String. For example, if a browser identifies itself as IE6
with the following User Agent String:
Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)
Then, the server can send back a different stylesheet to IE6. While this may seem
like a simple, easy solution, the problem occurs when browsers lie. Historically,
browsers have never exactly claimed to be which browser they are, and hence, it is
likely that you may send the wrong stylesheet to a browser.
It also involves a little overhead server-side to process the request according to
the browser's User Agent setting, and hence is not an ideal way to serve different
stylesheets to IE8 and below.
Stylesheets based on conditional comments
Conditional comments are HTML comments with special syntax that are understood
by IE9 and below. The following is a sample conditional comment:
<!--[if lt IE 9]>
<p>HTML Markup here</p>
<!--<![endif]-->
All browsers except Internet Explorer 9 and below ignore content within these con-
ditional comments. IE9 and below try to interpret the if condition within these com-
ments and selectively render the content if the version number of the IE browser
matches the one within the if condition.
Search WWH ::




Custom Search