Click to See Complete Forum and Search --> : Getting some CSS to validate
JavaHead Jonnie
09-25-2004, 07:29 AM
OK, as we know, IE sux0rs at CSS - you can only use :hover on <A> tags, not <ACRONYM> for example, so I've got an IE .htc file that allows :hove on any object, but bahvior: doesn't validate. Is there a way to get it to validate or be ignored by validators?
behavior: url("/includes/hover.htc");
Thanks & Regards, Jonnie
fredmv
10-02-2004, 03:37 AM
Conditional comments (http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp) may be a viable solution:<!--[if IE]>
<style type="text/css">
@import url(style.css);
</style>
<![endif]-->Even still though, I wouldn't worry about this too much. The validity of your code is important, yes, but in cases like this where you're using a non-standard CSS property... it shouldn't cause any trouble.
JavaHead Jonnie
10-02-2004, 04:18 AM
OK - that's a bit hackish and screws up the validity of my (X)HTML.
It's a PHP aplication so I'm going to cheat and use an if() whith an echo() based on the user-agent.
David Harrison
10-02-2004, 03:05 PM
Well since the .htc file contains JScript (I assume), then scripting must be enabled in IE for the file to be implemented. Therefore you could just use JavaScript to add in the file liks so:</head>
<body>
<script type="text/javascript">//<![CDATA[
var theHead=document.getElementsByTagName("head")[0];
var theStyles=document.createElement("style");
theStyles.type="text/css";
var naughtyRules="*{behavior: url(/includes/hover.htc);}";
naughtyRules=document.createTextNode(naughtyRules);
theStyles.appendChild(naughtyRules);
theHead.appendChild(theStyles);
//]]></script>That will append a new style tag in the head section and therefore your XHTML and CSS will remain valid while IE will have the effect applied to it. With this method you need no server-side code or browser sniffing going on. You could also put the JavaScript code in an external file or a function or both and get it out of the way.
JavaHead Jonnie
10-02-2004, 03:22 PM
I think I'll go for the PHP method (No offence) becuase I'm pushing my limit on script size and this way it'll give faster load times/save me bandwidth for non IE users.
Also, the site's already PHP/MySQL based so it's not problem adding the code.
David Harrison
10-02-2004, 03:30 PM
OK, no harm no foul. :)