Forum Moderators: open

Message Too Old, No Replies

placement of script that refers to style

         

kam79

3:25 am on Dec 3, 2006 (gmt 0)

10+ Year Member



hi,
i'm trying to use the min-/max-width technique for IE, described in various threads. i'm using the following code, just not sure where to put it.

<script type="text/javascript">
<!--
#page_wrapper, #content {
width: expression(document.body.clientWidth < 602? "600px" : document.body.clientWidth > 802? "800px: : "auto");
//-->}
</script>

i can get IE to recognize it if i put it in my css, but of course then my css doesn't validate. i put it in the <head> of my page, but i must have something wrong because IE isn't recognizing it. should i put it in an external file? do i need to include the <style> tags somewhere? if so where?

penders

4:16 pm on Dec 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your 'code' is CSS, and should be treated as such. It is not JavaScript, as you have defined it above, by placing it within <script> tags. It should be within <style type="text/css">...</style> tags if you want it in your <head> section.

But, as you have found, it is not valid CSS - since it uses IE's expression() to use a snippet of JS within the CSS file itself. This will not validate.

You either have to put up with your CSS not validating, or put your IE only CSS in a separate file and include it with a conditional comment - this, I think, is the best solution, if you must this form of JS in your CSS file.

In your <head> section:

<!--[if lte IE 6]> 
<link rel="stylesheet" type="text/css" href="ieonly.css">
<![endif]-->

This will pull in the "ieonly.css" CSS file only for IE, less than or equal to version 6.

kam79

4:12 am on Dec 6, 2006 (gmt 0)

10+ Year Member



thanks penders - that makes sense, but i can't get it to work.

i put the following in a file called ieonly.css, inside the style_sheets folder:

#page_wrapper, #content {
width: expression(document.body.clientWidth < 602? "600px" : document.body.clientWidth > 802? "800px: : "auto");
}

i put this code in the <head>:

<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="style_sheets/ieonly.css">
<![endif]-->

should ie be recognizing it when i view the html file from html-kit, or will it only work when it's live? or does this particular css file have to be at the root level for some reason? or do i have something wrong in the expression()?

thanks,
kam

Bernard Marx

8:19 am on Dec 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have a JS syntax error. It may have some bearing on the matter ;)

802? "800px[red][b]:[/b][/red] : "auto"

[edited by: Bernard_Marx at 8:20 am (utc) on Dec. 6, 2006]