-1

i have a site that uses textfields. in firefox, i use css. but when i open my site in google chrome, i got different design of my site.

i think the solution for that is having a diferent css file for different browser. so i need to know the browser used by the following users. then change the link for css.. example:

<link href='Site_Css/firefox.css' rel='stylesheet' type='text/css' />

then if the user uses google chrome,

<link href='Site_Css/firefox.css' rel='stylesheet' type='text/css' />
  • 2
    You rarely need different style sheets for different browsers these days. The only thing I ever need is a few fixes for IE6,7 and 8. I'd seriously look at why you need to do this – it's unusual. – Rich Bradshaw May 19 '13 at 11:11
  • 1
    Unless you're talking about the styling of `input` elements, chances are that whenever you get different results, you have errors in your HTML or your CSS. Different browsers respond differently to errors. But code that validates, only very rarely results in different browser behavious these days. – Mr Lister May 19 '13 at 11:16

2 Answers2

0

You can pull the browser property of get_browser(). Do note though that this is costly.

As a side note, there shouldn't really be a need to include separate stylesheets for Chrome and Firefox. Different browsers do handle certain CSS properties differently, but there is almost always a pure-CSS workaround.

James Donnelly
  • 126,410
  • 34
  • 208
  • 218
0
<?php

// check what browser the visitor is using
  $user_agent = $_SERVER['HTTP_USER_AGENT'];

// This bit differentiates IE from Opera
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) 
    { 
      print
        'This is Internet Explorer. (Insert joke here)';        
    } 
    elseif(preg_match('/mozilla/i',$u_agent) && !preg_match('/compatible/', $userAgent)) 
    { 
      print
        'This is FireFox.';
    } 
// let Chrome be recognized as Safari
    elseif(preg_match('/webkit/i',$u_agent)) 
    { 
      print
        'This is either Chrome or Safari.';
    } 
    elseif(preg_match('/Opera/i',$u_agent)) 
    { 
      print
        'This is Opera. Like to live on the edge, huh?';
    } 
    elseif(preg_match('/Netscape/i',$u_agent)) 
    { 
      print
        'This is Netscape, and you really need to upgrade.';
    } 

?>
Yogus
  • 2,307
  • 5
  • 20
  • 38