Dynamic CSS? Jul12 '04
The question of the day is...
Can a static CSS file be dynamically written to the page? It seems possible, but I have yet to try.
By using PHP, in combination with a few lines in an .htaccess file, CSS can and should be able to be dynamically written to the page.
I know this, because I do the same thing with my RSS feed, which is an XML file, that uses PHP to pull out the data from the database. But, you wonder, how does an XML file utilize the powers of PHP? Doesn’t a file that uses PHP have to have the extension, ".php?"
The answer is obviously no. All you have to do is create an .htaccess file, and put a line in there that says:
AddType php-cgi .html .htm .xml
Notice the ".xml" extension, along with ".html" and ".htm." That means that any file with those extensions, THAT CONTAIN PHP CODE, will successfully be rendered as PHP.
Now... can’t I do the same for CSS?
If so, couldn’t CSS be put into a database, and dynamically pulled out?
It seems so trivial, and most readers with knowledge of this are probably thinking, "Duh, it’s already been tried."
But I’m not sure it has...
Add Feedback (view all)
Leave feedback
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Similar Entries
- Swap banner image with CSS and PHP (795 recent visits)
- CSS class, or HTML tag? (14 recent visits)
- CSS font-size dialogue! (123 recent visits)
- Misleading CSS link declarations (10 recent visits)
- CSS print style sheet (12 recent visits)
- CSS adjacent sibling selectors and IE 6 (396 recent visits)
Stats
5 unique visits since August 2008
Recent Referrers (click)
- http://matthom.com/blog/view/s
- feedback
- feedback
- http://matthom.com/archives/ca
- feedback
- http://matthom.com/blog/view/s
- feedback
- feedback
- http://matthom.com/archives/ca
- feedback
- http://matthom.com/blog/view/s
- feedback
- feedback
- http://matthom.com/archives/ca
- feedback
- http://matthom.com/blog/view/s
- feedback
I've used a nice PHP driven style sheet in the past that would cook up a random colourscheme on every page load (one that works and not one that ma ... Read more.