PDA

View Full Version : dynamically load css into a web page with php?



talan3000
12-19-2007, 10:11 PM
Is it possible to do a browser detection and instead of redirecting to a compatible page have a compatible css document load using php?

I'm rebuilding my website right now. I have three style sheets , one for ie7, one for Firefox, and one for ie6 and older - the same pages with the same info, the only thing that changes from browser to browser are the style sheets.

It would be real nice if I didn't have to make three different web sites just for it to be seen on all browsers.

to the moderators; Not trying to do over kill but I'm also going to post this in the css forum just in case they know something the php guys don't

brentnicholas
12-20-2007, 11:04 PM
Firstly... are you a php programmer?

If so, wouldn't you just sniff the agent type and build an if/else routine to include the correct sytle sheet?

I'm a ColdFusion programmer and the way it works on our end, is that the CF engine knows the agent type, processes the template and spits out HTML based on the code in the template... if php is the same this should work.

If you're not a php programmer... reasearch php code on: file includes, browser agent sniffing, and if/else routines.

Hope this helped.

BN

lord_havoc
12-21-2007, 01:06 AM
Couldn't you just use conditional comments?



<!--[if lte IE 6]>
Link to IE 6 CSS
<![endif]-->

<!--[if IE 7]>
Link to IE 7 CSS
<![endif]-->

<!--[if !IE]>
Link to other stylesheet
<![endif]-->

Eternal_Howl
12-21-2007, 09:20 AM
I'm fairly new to CSS and I guess I'm not sure of your layout, but found that persistence paid off and I didn't require separate style sheets for the site to look the same across various browsers or even different versions of the same browser.

One thing I learned was test and design for Firefox first - and then look at what's going wrong in the non-webstandards compliant browsers that is Internet Explorer afterwards. I learned this backwards. My site requires images as opposed to being text based so this makes it a bit of a 'mare as I'm not relying on scripted galleries per se. Most sites I've seen that talk about css are mainly dealing with text based layouts, which wasn't very helpful for me.