HTML Tutorial


 /help/HTML Help Forum   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
IE conditional inline style
Post new topic   Reply to topic    HTML Help Forum -> DHTML
View previous topic :: View next topic  
Author Message
verlager



Joined: 23 Jan 2009
Posts: 4

PostPosted: Sat Jan 24, 2009 12:13 am     IE conditional inline style Reply with quote

I have a website that needs special code for IE7 and above. I want to insert a declaration in realtime into an inline style, based on an IE conditional test.

Code:
<div style="margin-bottom:10px;
<!--[if IE ]>
margin-bottom:5px
<![endif]-->
>"


But that isn't the correct syntax for inserting text/code using IE conditionals. I tried using javascript document.write but that simply echoed "document.write("margin-bottom:5px") literally. What to do?
sticks464



Joined: 31 Dec 2006
Posts: 2625

PostPosted: Sat Jan 24, 2009 6:55 am     Reply with quote

Conditional statements are meant for the head section. Give the div an id
Code:
<div id="mydiv" style="margin-bottom:10px;


Then put the conditional statement as the last entry before the ending head tag
Code:
<!--[if IE ]>
<style type="text/css">
#mydiv {margin-bottom:5px;}
</style>
<![endif]-->
</head>

This will affect all versions of IE including IE8 so you might want to specify which version you want


Code:
<!--[if lte IE 7 ]>
will affect IE7 and older


Code:
<!--[if IE 7 ]>
will affect only IE7
verlager



Joined: 23 Jan 2009
Posts: 4

PostPosted: Sat Jan 24, 2009 10:22 am     Bordering on coding for three web browsers. Reply with quote

I'm sure you're right, but I used the IE conditionals in the menu header portion of my web site and it worked perfectly.

Validation in xhtml 1.1 was another story, as a dozen errors popped up. I had to edit my code, not by escaping with "\", but choosing the safer path with "&lt;" and "&gt;". Notice the "div onclick" (!onClick) which means that anywhere else they right click returns them to the home page.

Code:

<div onclick="location.href='../index.shtml';" style="margin-top:10px; margin-bottom:0;
&lt;!--[if IE ]&gt;margin-bottom:25px&lt;![endif]--&gt;">
<!--#include virtual="./menu.shtml" -->
<br style="clear:both" />
</div>


I was unable to delete my post here. It says edit/delete but then I couldn't find how to delete it.

Ain't is funny that we're essentially coding to account for anomalies in three web browsers: gecko, webkit and IE ? And all I wanted to do was write code to W3C standards. No such luck. I don't want to lose 40% of my readers by redirecting IE 7+ clients to FF, but I just might, as the economy tanks here in the USA. (http://communitychessclub.com)
sticks464



Joined: 31 Dec 2006
Posts: 2625

PostPosted: Sat Jan 24, 2009 11:03 am     Reply with quote

All browsers are getting better at rendering code to standards except IE who Microsoft has promised since 1995 that each release was better. I think they're going backwards since none have come close to standards.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum -> DHTML All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial