Library tutorials & articles

Creating Dynamic Style Sheets Using ASP

Generating the CSS

Now that we have tools to detect the type of browser, it is very simple to customize the output of the style sheet. We start by changing the ASP content type to that of a CSS style sheet. Then we include the browser detection code in BrowserDetect.asp. With these two preliminary steps complete, we just use simple IF...THen code to specify where and when a given style command should be part of our definition.

<% Response.ContentType = "text/css" %>
<!--#include file="BrowserDetect.asp"-->
#SampleBox {
<% If Not NS4 Then %>
    font-family: Tahoma, Arial, sans-serif;
    font-size: 10pt;
<% Else %>
    fontfamily: Tahoma, Arial, sans-serif;
    fontsize: 10pt;
<% End If %>
<% If css2compatible Then %>
    /* in css2 standard the width of the box does not invlude its padding, borders, or margins */
    width: 230px;
    height: 80px;
    padding: 10px;
<% Else %>
    /* in older browsers, padding in considered part of a box's width and height */
    width: 250px;
    height: 100px;
    padding: 10px;
<% End If %>
}

The above code accounts for two circumstances in which you'd wnt to customize CSS output, but there could be many more. The first is that one corrects for improperly implemented style commands in Netscape 4, which doesn't use the hyphen in font commands as it should. The second accounts for a rather critical clarification of the way padding should be implemented that was not corrected until version 6 or IE and Netscape.

Comments

  1. 15 Jan 2003 at 21:36

    There is also a very simple service one can use for browser detection.  It's a service, so it's always up to date with the latest browsers.  To take a peek, check out http://www.whatsthatbrowser.com

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Creating Dynamic Style Sheets Using ASP.

Leave a comment

Sign in or Join us (it's free).

Thomas C. Carpe I have been working in IT since 1993. I founded CarpeDiem Business Internet Systems in 1995. In 2000 we incroporated and took on two partners. Its really a grat lot of fun, and I enjoy working on t...
AddThis

Related podcasts

  • Scott Guthrie

    Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.

We'd love to hear what you think! Submit ideas or give us feedback