tags:

views:

5803

answers:

7

Firefox 3.5 now supports the nth-* pseudoclass, which was what I was using to target my css for Safari and Chrome. Now Firefox reads those too, causing minor layout issues. Does anyone know a way to specifically target FF 3.5+?

BODY:nth-of-type(1) #topsearch input[type=submit] /* Safari 3.1+ and Chrome */ { 
     height:19px 
}
+3  A: 

How about this, I tested it in Safari 4 and the height is 19px, in Firefox 3.5 the height displays as 39px.

<style>

BODY:nth-of-type(1) #topsearch input[type=submit] /* Safari 3.1+ and Chrome */ { height:19px }      
BODY:nth-of-type(1) #topsearch input[type=submit], x:-moz-any-link, x:default { height: 39px; }

</style>
Paul
The answer I needed, thanks!
+5  A: 

On a "religious" note, we shouldn't be using CSS to target any browser. Unfortunately due to IE being waaaay behind on supporting CSS features (and all the bugs) hacks have been applied to target CSS for a given browser.

The Conditional Comments that IE uses... although ugly... do provide a handy mechanism for targeting a browser (and version)... I almost wish other browsers supported this.

I've seen a few sites do this... which is an interesting approach to handling targeting of various browsers.

<head>
  <style>
    body.safari form input{
      /*special styles for Safari*/
    }
    body.firefox form input{
      /*special styles for Firefox*/
    } 
    body.firefox.v3-5 form input{
      /*special styles for Firefox 3.5*/
    } 
</style>
</head>
<body>
  <script>
    //run code here, that sets the class and or id attribute on the body tag...
  </script>

In the long run, they are all hacks... it just depends what kind of hacks you're willing to live with ;-)

scunliffe
+4  A: 

CSS Browser selector lets you write CSS that targets specific browsers, without worrying about hacks. I cannot recommend it highly enough.

Bruce McLeod
@Bruce - that's a nice tool! It basically does a similar trick to what I posted but adds the classes to the html element. Since that is the definitive top element, just specifying .gecko or .win or .safari handles everything like a charm!
scunliffe
@Bruce - one minor catch... as far as I can tell (at the moment) that tool won't provide a special class for ff3-5. That said, you can specifically target safari and chrome.
scunliffe
A: 

Incidentally the "BODY:nth-of-type(1) ..." syntax breaks YUI compressor's ability to minify CSS. Instead I use "body:first-of-type ...".

A: 

My approach using a PHP class to detect os, browser and browser version. You can target any version of almost any browser on any operating system.

A: 

using http://rafael.adm.br/css%5Fbrowser%5Fselector/

just substitute this part:

is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3'

for this part:

is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3_5':is('firefox/3')?g+' ff3'

that should do the trick

PS: if you want to also catch other 3.x versions you might want to add:

is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3_5':is('firefox/3.6')?g+' ff3_5':is('firefox/3.8')?g+' ff3_5':is('firefox/3')?g+' ff3'

Casper
A: 

This works:

@media screen and (-webkit-min-device-pixel-ratio:0){
    #topsearch input[type=submit] { height:19px; }
}}

That targets newer WebKit browsers, and not Gecko or Trident.

Steve Paulo