views:

4231

answers:

2

I need to do chrome/opera hacks because of a font replacement script wanted by the client that breaks things... this is sad but everything is working in IE6-7, FF2-3 and Safari. I have no way of fixing the script itself, I can only hack around it using CSS and HTML.

I'm trying to do something in the lines of :

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

Is it possible?

I saw this way of doing chrome specific fixes like:

body:nth-of-type(1) .elementOrClassName
{
/* properties go here */
}

Is this working? Is there a simpler way? What about Opera?

Thanks!

A: 

I haven't tested this solution, but according to this blog entry, you could try the following for Chrome:

if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
{
     var chromeCss = document.createElement("link");

     chromeCss.rel = "stylesheet";
     chromeCss.href = "ChromeStyle.css";

     document.getElementsByTagName("head")[0].appendChild(chromeCss);
}
Lobstrosity
He said he can only touch the HTML and CSS, but not the JavaScript.
Nosredna
The way I read it, he can't modify the external JavaScript files that do the actual font replacement, but if he can edit the HTML, he could always add a script tag :)
Lobstrosity
Yes I can, but I'd rather not if possible. If you tell me that's the only way then... I guess I don't have any other options !
marcgg
+5  A: 

A clean javascript way to do this: http://rafael.adm.br/css_browser_selector/

It ads browser specific classes to the body tag of your html which you can use in your css like:

.opera #thingie, .chrome #thingie {
  do: this;
}

Hope this helps.

Thomas Maas
This is not exactly what I was looking for, but it's a clean enought approach since apparently there is no pure CSS way of doing that. Thanks!
marcgg
It may not be "pure" but it solves the problem! thanks.
fmz