Where's the website?

Our advanced systems detected you're trying to access porcupine colors by an old and deprecated browser like Internet Explorer 7 or even 6!
This website uses some technologies which can't be detected from such an outdated software.

We urge you to try again by using one of the following browsers: Google Chrome, Apple Safari, Opera ή Mozilla Firefox.

porcupine colors

Selecting different styles for different browsers

Applying different stylesheets according to different browsers is a job I hate to do. However, sometimes you need to get dirty.

The following code is not exactly a hack but a combination of rules applied to a website according to different browsers and according to different versions of Internet Explorer (yes, IE is always the problem).

So I had a stylesheet which applied well to Firefox, Opera and Internet Explorer 7, but not to IE6 or to previous versions. Let’s name it global.css.

Step #1

In order to hide the style from all versions of IE I imported like this:

<style type="text/css">@import "global.css" screen;</style>

The mediatype “screen” is the key which hides the style from IE browsers. However, the @import rule is not recognizable by all browsers, so pay attention how you use it.

Step #2

Now the style is applied to Firefox and Opera but not to IE. In order to move on I had to use some conditional comments. Here is an introduction to conditional comments and here is an article why conditional comments are good.

The following expressions are recognized by practically every browser:

<!--[if ! IE 7]><style type="text/css"> @import old.css </style><![endif]>
<!--[if IE 7]><style type="text/css"> @import global.css </style><![endif]>

Things are pretty simple here. The first line requires the old.css file to be loaded when the browser is not IE7, while the second one asks for the global.css in case that the visitor of the website uses IE7.

So now everything runs pretty smoothly and everyone is happy except for me who had to search for hours to find this solution. Hope you find it useful.

Share this post or make it forever yours:

# Journal Feeds

0 Comments

Add a comment


Please help us crash spam and answer to the question below *:
The name of this website is:
porcupine...
Remember my personal info
Notify me of new comments

How to add better comments:

  • Remember to fill in all inputs with an asterisk like this one: *
  • Get a gravatar Gravatar
  • Tags you may use: a, blockquote, em, strong
  • Please don't insult and don't spam.
  • Wait 5' in case you eant to add a second comment.