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 a suburb of 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.
Popular Pages
- Fast rounded corners in Photoshop (4153 recent visits)
- PHP – passing variables across pages (1559 recent visits)
- JavaScript set selected on load (1290 recent visits)
- Removing all child nodes from an element (882 recent visits)
- iPod songs out of order? (747 recent visits)
- Britney - Everytime piano tab (669 recent visits)
- Firefox 3 smart address bar: wildcard search (633 recent visits)
- MySQL LEFT JOIN syntax (543 recent visits)
- Breathe Me - Sia (508 recent visits)
- Tumblr: how blogging should be (405 recent visits)
Similar Entries
- Swap banner image with CSS and PHP (117 recent visits)
- CSS class, or HTML tag? (2 recent visits)
- CSS font-size dialogue! (5 recent visits)
- Misleading CSS link declarations (1 recent visits)
- CSS print style sheet (0 recent visits)
- CSS adjacent sibling selectors and IE 6 (67 recent visits)
Stats
0 unique visits since Jul12 '04
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.