Who says ASP files have to serve just web pages? There's
no reason whatsoever to limit your scripting to HTML based
files. ASP works perfectly well in any number of different
situations. This tip will illustrate that fact with a
simple dynamically generated style sheet.
To keep from boring you with details, I'm going to let the
code sample speak for itself. Here's the listing for a plain
old HTML file that uses a style sheet:
<title>ASP-Scripted CSS File Demo</title>
<link rel="stylesheet" type="text/css" href="css.asp">
<p class="sample">This is a test!</p>
Notice the stylesheet links to an ASP file. This works fine
as it is. If you want to use this sample and still have
your style sheets have a .css extension then you'll need
to configue your server to send .css files through the
Without any further hesitation, here's that css.asp file:
I couldn't come up with anything
exticing so I simply vary the font size based on the date, but
you have access to all the standard ASP functionality just like
you normally would and can do whatever you want. The only
difference is that instead of outputting valid HTML you need
to output valid styles.
One of our readers has discovered that some browsers don't exactly
like style sheets that are generated by an ASP page.
Here's a quick fix she sent in to help address the issue.
If you want to use dynamic style sheets you also need to include this
line of code in css.asp (or whatever your css file is called), otherwise
it may not be recognised as css.
<% Response.ContentType = "text/css" %>
The line should be included at the top of your script
and sets the MIME type returned with the file's headers.
Thanks for the head's up Amanda!