站内搜索
广告
Creating Dynamic Cascading Style Sheets with ASP
作者:    来源:    点击:    日期:2007-3-18 23:32:30   

The ASP page dynastyle.asp can now create the correct properties of the style sheet rules dynamically based on the querystring value. For this article, I decided to make the code for dynastyle.asp fairly simple - the style sheet contents are simply hard-coded in. A more flexible solution, though, would be to have the style sheet values pulled from a database. The code for dynastyle.asp can be seen below:

<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<%
Dim cardtype, light_color, dark_color, cardimage

'Read in the querystring value
cardtype = request.querystring("cardtype")

'Set our stylesheet values based on the
'querystring value passed in
select case cardtype
  case "gold"
    light_color = "gold"
    dark_color = "navy"    
    cardimage = "goldcard.gif"
  case "platinum"
    light_color = "silver"
    dark_color = "green"    
    cardimage = "platinumcard.gif"
  case "standard"
    light_color = "#ddffdd"
    dark_color = "#339933"    
    cardimage = "standardcard.gif"
end select
%>

h2 { FONT-FAMILY: Arial; FONT-STYLE: italic;
     COLOR: <%= dark_color %> }
     
li {LIST-STYLE-IMAGE: URL("<%= cardimage %>");}

table.transactions{BACKGROUND-COLOR:<%= light_color %>;
    COLOR:<%= dark_color %>;
    BORDER: THICK DOUBLE <%= dark_color %>;}

.reverse{BACKGROUND-COLOR:<%= dark_color %>;
    COLOR:<%= light_color %>;}




That's all there is to it. Other triggers, such as cookies and session variables, can also be used to vary the style sheet content from one user to another.


Creating Dynamic Cascading Style Sheets with ASP 评论