Server side scripting of styles to suit the browser
Archive - Originally posted on "The Horse's Mouth" - 2005-09-12 14:54:33 - Graham Ellis
I'm updating our web site and, naturally, I want to use current standards for my HTML, and some of the newer features such as style sheets to make the web site cleaner and easier to navigate. But I was faced with a conflict - I want to be able to support customers who are browsing to our site with older browsers, AND I want to be able to make full use of style sheets and other newer facilities for those users with recent client software.
A first approach of attempting to come up with a set of style sheets to work with all our target browsers turned ino something of a complex exercise. It's pretty disheartening to spend a lot of time applying a fix to "kludge" one browser just to find that you've upset another. and the resulting file gets twice as hard to maintain each time a new set of browser support is added. Quite simply, it's not practical to come up with a single set of HTML and CSS that will well on all the older browsers AND will support the facilities of the newer ones that we wish to use
Our solution is to add PHP code into the style sheet ... and to tell the web server that .css files are to be parsed through the PHP module. It works a treat, and we set a header line to ensure the browser is told it's actually getting .css data. We can even pass parameters into the style sheet - in this example, to tell it to use a larger base font size to suit the accessability requirements of the disability discrimination act if need be.