Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML conditional comments (if !IE)

Status
Not open for further replies.

Zhris

Programmer
Aug 5, 2008
254
GB
If the users browser is IE 4 or lower then I don't want to load the external stylesheet. To do this I have tried using 2 separate conditions, however the negative condition (which is there to ensure all other browsers except IE fall into it) fails to work properly. I have provided my 3 attempts of creating a negative condition, which is meant to refer to any browser which isn't IE.

Code:
Attempt 1:
<!--[if !IE]>
	<LINK REL="stylesheet" TYPE="text/css" HREF="Styles/Styles.css"/>
<![endif]-->

Attempt 2:
<![if !IE]>
	<LINK REL="stylesheet" TYPE="text/css" HREF="Styles/Styles.css"/>
<![endif]>

Attempt 3:
<!--[if !IE]><![IGNORE[--><![IGNORE[]]>
	<LINK REL="stylesheet" TYPE="text/css" HREF="Styles/Styles.css"/>
<!--<![endif]-->

Any suggestions why any of the above 3 conditions do not work correctly?

Thank you,

Chris
 
IE browsers pre version 5 do not know about conditional comments so they will just ignore the link tags anway.

Browsers that aren't IE won't see the link tags either because they are in comments - only IE knows about conditional comments.

Your comments are saying that if the browser ISN'T IE then do this... however, ONLY IE will ever read the comment as anything other than a comment.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Thank you for replying,

Is there any "proper" solution around this?

My last option would be to use a 2nd stylesheet just for browsers lower than 5 ( <!--[if lt IE 5]> ), which would mean going through every id/class etc and ensuring that there are no attributes within e.g.

#outer {width:100px;height:100px}
to...
#outer {}

I am relatively new to cross browser design techniques.

Chris

 
I am relatively new to cross browser design techniques.

So here's some advice... don't worry about IE 4, or NN 4 for that matter.

Until about 2 years ago, I always tried to make sure all my work looked good in IE5 and 5.5 - but now I just see IE 6 as the minimum.

IE 4 is over 8 years old now, and I very much doubt you will have any users (or perhaps less than 1%) visiting sites with browsers these old.

It's the 80/20 rule... or in this case, more like a 95/5 rule. You're spending 95% of your time trying to get something for 5% of your users. It's just not worth it.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I agree with Dan. IE4 was released in 1997 (so it is actually 11 years old) and superseded by IE5 in 1999 (so that was 9 years ago). There is no reason why you would support a browser that old.

Your logic for your workaround fails again, on the same principles as Foamcow showed you. You're saying "If browser is IE before version 5" however IE browser before version 5 cannot read this comment -- that's why it cannot work.

Unless you have a user base that uses IE4 (in that case I would seriously suggest you urge them to upgrade), you should not care how your page looks on such an old browser. Focus on the current browsers instead: FF2, FF3, Opera, Safari, IE6, IE7, Google Chrome...

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
My advice would be as the others have said. Forget V4 browsers! When I answered this last night I thought it said IE5 - which personally, I don't bother with. Anyone using a browser that old is used to a completely broken internet experience anyway. They don't care.

Focus on FF2, FF3, Safari (and perhaps IE7) for your 'base' stylesheets.

Then use a conditional comment to serve a few additional/over-riding styles for IE6 if needed. On rare occassions you may need a tweak here or there for IE7. I tend to find that I can normally write code that behaves in all the current browsers and only need to 'fix' IE6.

Utilise the 'Cascade' of Cascading Style Sheets. Instead of completely overwriting all your styles add to them - perhaps over-riding a few properties to accomodate IE6's box model.

Include that extra sheet using a conditional comment.

Code:
<!--[if lt IE 7]>
	<style type="text/css" media="screen">	
		@import "/css/ie6.css";		
	</style>
<![endif]-->


--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Hey,

Thank you all very much for your comments.

I have currently being focussed on making sure "every" browser will work efficiently, and so far I normally don't have problems with IE 5.01+ except for the odd time I must ensure overflow is supported by scrollbars.

I didn't ever realise that this wasn't such a big issue. I guess this is partially due to the fact that while looking through others browser shots I notice that in most cases their website works fine from IE 4+.

W3School statistics show that the usage of IE 5 has been dramatically dropping this year from 1.5% of all browsers in January to just 0.1% in Auguest (1 in 1000). So who knows how low IE 4 will be, also baring in mind that it isn't even part of their statistics re-assures me of its irrelevence. I must also mention that my 1 of my larger website statistics show: IE 5 = 0.05%, and nobody with IE 4 has ever visited.

As for IE 8, I haven't had any problems except with anchors where they act as inline elements even without text. Therefore I simply used the property {display: none;}. After all IE 8 may be in testing, if I am building websites now I would want to ensure that they will work in future browsers as best as possible to reduce the chances of having to re-work on the website again.

Thank you everyone once again, I feel much more confident that I have wasted alot of time focussing on unneccessary browser fixes.

Chris

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top