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

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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?

QUICK TIP:
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:

<html>
<head>
<title>ASP-Scripted CSS File Demo</title>
<link rel="stylesheet" type="text/css" href="css.asp">
</head>
<body>
<p class="sample">This is a test!</p>
</body>
</html>

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:

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

Update:

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: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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