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...

Categories: Apache , CSS

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

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.

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.

Contact Matt

Popular Pages

  1. Fast rounded corners in Photoshop (4153 recent visits)
  2. PHP – passing variables across pages (1559 recent visits)
  3. JavaScript set selected on load (1290 recent visits)
  4. Removing all child nodes from an element (882 recent visits)
  5. iPod songs out of order? (747 recent visits)
  6. Britney - Everytime piano tab (669 recent visits)
  7. Firefox 3 smart address bar: wildcard search (633 recent visits)
  8. MySQL LEFT JOIN syntax (543 recent visits)
  9. Breathe Me - Sia (508 recent visits)
  10. Tumblr: how blogging should be (405 recent visits)

Similar Entries

Stats

0 unique visits since Jul12 '04

Recent Referrers (click)

Syndicate

Advertisements