views:

3573

answers:

8

Hi,

Is there such a thing as conditional comments for Chrome?

I have a page that renders differently in chrome compared to firefox.

Thanks

+6  A: 
<!--[if IE 8]><div id="bodyContainer" class="IE8"><![endif]-->
<!--[if !IE]>--><div id="bodyContainer" class="W3C"><!--<![endif]-->
<script type="text/javascript"> 
    if (navigator.userAgent.toLowerCase().match('chrome') && document.getElementById('bodyContainer'))
     document.getElementById('bodyContainer').className = document.getElementById('bodyContainer').className + " chrome";
</script>

Then you use CSS to tweak your styles specifically for Chrome.

DmitryK
How silly of me, I never considered JS :-)
Sir Psycho
+2  A: 

Both HTML conditional comments and Javascript conditional compilation directives are only supported by Internet Explorer 4-8 to the best of my knowledge.

David Parunakian
A: 
p.g.l.hall
Users with JS turned off are too few to care about :-)
Sir Psycho
I disagree. Add-ons like NoScript for Firefox are a lot more common than you would think.
Justin R.
Common to tech heads and developers, not mums, dads and common folk who use the web.
Sir Psycho
+7  A: 

You can target WebKit based browsers using this in your CSS

@media screen and (-webkit-min-device-pixel-ratio:0) { 

Body {}

}

Perhaps this will help?

George Wiscombe
+1  A: 
Lorenzo816
A: 

@media screen and (-webkit-min-device-pixel-ratio:0) { Body {} }

...works great for me. Thanks George!

Ryan
A: 

Seriously? Why is this not simple like the Ie fix. Granted, everyone hates ie, but why not something simple for chrome? I mean, I'm looking at what's up above here, and - yeah, maybe it works - but why is this example not targeting a CSS document? I thought that's what the purpose of this was? Not just to say "Oh, hai Chrome!"

  • JC
james