TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   what method do you use with php when displaying a stylesheet? (http://www.talkphp.com/absolute-beginners/3825-what-method-do-you-use-php-when-displaying-stylesheet.html)

sarmenhb 01-02-2009 10:08 AM

what method do you use with php when displaying a stylesheet?
 
this is how i display a style sheet for whatever browser that opens the page.

Code:

function style() {
$browser = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE6.0/',$browser)) {
echo "ie6.css";
}

if(preg_match('/Firefox/',$browser)) {
echo "firefox.css";
}
}

//then in the html i put something like this

<head>
<link href="css/<?php style(); ?>" type="text/css" rel="stylesheet">
</head>

is there a better method to do than doing it this way? since this is the only way that i know i'm wasting more time by creating a stylesheet for every browser that exists than finding another way.

whats another way of doing this??


thanks

enzochi@gmail.com 01-02-2009 12:41 PM

you could just use HTML conditional statements:

<!--[if IE]>
<link href="/includes/ie-fixes.css" rel="stylesheet" type="text/css" />
<![endif]-->

there is also get_browser() for php:

$browser = get_browser(null, true);
print_r($browser);

personally I use the html method.. i've used the php method and i like it but it won't work on all servers if it's not setup properly.

sketchMedia 01-02-2009 02:20 PM

I usually use a main style sheet which holds all styles that good browsers render properly and for the retarded browsers i use conditional statements to overwrite specific styles:

HTML Code:

<link rel="stylesheet" href="main.css" type="text/css" />
<!--[if lte IE 6]>
    <link rel="stylesheet" type="text/css" href="ie-6.css" />
<![endif]-->

<!--[if IE 7]>
    <link rel="stylesheet" type="text/css" href="ie-7.css" />
<![endif]-->


sarmenhb 01-02-2009 09:25 PM

thanks, but what do you put for other browsers?

like firefox, chrome, etc do you have to write a javascript for each browser?

cause i noticed chrome acts a little different since its a mozilla engine.

enzochi@gmail.com 01-02-2009 09:46 PM

the conditionals only work for IE (I can't find anywhere that would suggest different). The way I work this out is to develop for FF/Safari/Opera. Then make it work in IE. Those three seem to work better with standard code. IE really needs the shims to get everything to look correct. And these three cover the basic html render engines. These same rules apply for JavaScript too..

here is a link for the conditionals..
http://www.dedestruct.com/2008/04/03...onal-comments/

sketchMedia 01-02-2009 10:05 PM

Chrome is built on webkit, which is the very same engine as safari. General rule of thumb (i find anyway) if it works in chrome, it will generally work in safari.

sarmenhb 01-03-2009 03:22 AM

how about i start working on a project to make a major reset either stylesheet or php file that will be included into a page and make all major browsers all work the same as a primary browser in this case be firefox. if anyone is interested in helping out let me know.

we gotta end this problem.

Dr John 01-08-2009 10:16 AM

All you need to do is design for Firefox, correct for IE using conditional statements, and that's it.

There is no need what so ever to have a separate css file for each browser, because if it works in FF, it should work in all modern browsers. Browser sniffing is not used now. Especially as some browsers can pretend to be other browsers and thus feed your script duff data.

maZtah 01-08-2009 12:01 PM

The easiest way is to use a framework really. The frameworks handles the mass reset etc.

Read this thread http://www.talkphp.com/xhtml-html-cs...-bluetrip.html for a good framework.

CoryMathews 01-08-2009 02:36 PM

If you actually know css you can almost always get it down to 1 style sheet and not have to worry about this at all. However every now and then ie will act up and you can just use the html conditions as stated above to fix this.

The best way to avoid this is to have all 4 browsers up at once (FF/Opera/Chrome/IE7) and after every css change refresh the page one all 4 until you get it right in all 4. Then this whole mess can be avoided. It might take a little bit longer but its much easier once it works.


All times are GMT. The time now is 01:36 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0