 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
verlager
Joined: 23 Jan 2009 Posts: 4
|
Posted: Sat Jan 24, 2009 12:13 am IE conditional inline style |
|
|
|
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: 2631
|
Posted: Sat Jan 24, 2009 6:55 am |
|
|
|
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
|
Posted: Sat Jan 24, 2009 10:22 am Bordering on coding for three web browsers. |
|
|
|
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 "<" and ">". 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;
<!--[if IE ]>margin-bottom:25px<![endif]-->">
<!--#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: 2631
|
Posted: Sat Jan 24, 2009 11:03 am |
|
|
|
| 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. |
|
|
|
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
|
|
|
|
|
 |
|
|
|
|
|
|
|