ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
An Overview of ASP.NET
Connections, Commands, And Procedures
What is ASP?

Watch your Paths with Server.Transfer
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

ASP-Scripted Style Sheets

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

Without any further hesitation, here's that css.asp file:

    FONT-FAMILY: Arial;
    FONT-SIZE: <%= Day(Date()) %>pt;
    FONT-STYLE: italic;
    FONT-WEIGHT: bold;
    COLOR: red;

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!

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers