站内搜索
分类列表
本类阅读排行
本类推荐文章
- ASP技巧:让Len,Left,Right函数识...
- 用ASP实现IE地址栏参数的判断
- 如何实现ASP.NET网站个性化
- 如何在Asp.net中使用HtmlArea编辑...
- 用ASP.Net实现在线压缩和解压缩
- ASP实现不存在的网页就自动发送邮...
- 用ASP取出HTML里面的图片地址的函...
- asp.net跳转页面的三种方法比较
- 一个Winsock组件
- 用WinSock设计Chat程序(转)
- 在MFC应用中深入定制WebBrowser控...
- 这几天有人问关于编应.dll的问题,...
- 在Visual J++中编写ASP COM组件(转...
- 一个显示Grid的VBScript对象
- 好东西,快来看呀:(转载自中华网...
广告
Creating Dynamic Cascading Style Sheets with ASP
作者: 来源: 点击: 日期:2007-3-18 23:32:30
Cascading Style Sheets (CSS) are used to separate style and layout rules from HTML content. Normally these rules are stored in a separate file called a cascading style sheet. By setting properties for a tag or class once, its appearance is changed everywhere it is displayed. CSS can save you an incredible amount of time both developing and maintaining your Web sites, and they promote display consistency across multiple pages. For an introductory article on style sheets go to http://wdvl.internet.com/Authoring/Style/Sheets/. The remainder of this article will assume a working knowledge of style sheets.
If you are already using style sheets, you are probably using a static text file with a .CSS file extension. Sometimes you may want to change the look of a page based on dynamic content. One way to do this is by dynamically producing the cascading style sheet.
A Web page can specify to use a particular style sheet via the link tag. The link tag contains a number of attributes. For starters, the rel attribute should contain the value "stylesheet", while the type attribute of the link tag should be set to "text/css". Finally, the href attribute must point to a file containing the style rules. In using this href attribute you can make your stylesheets dynamic, since the href attribute can point to any file that returns the rules in text format, even an ASP page! A querystring parameter can be used to pass along dynamic values, which can be used to determine the content of the style sheet rules. The end result? Dynamic style sheets!
Why would you want to use dynamic style sheets? A simple example: Bank X uses ASP to produce pages where customers can view information about their credit card accounts. Bank X has three types of cards: standard, gold and platinum. One ASP page can be used to display transaction information for all three account types, and it can pass the type of card to a style sheet generating ASP-page; the style sheet generated would be appropriate to the user's card type.
So, let's look at some code! First, here's what the style sheet link tag looks like:
<link rel="stylesheet"
href="dynastyle.asp?cardtype=<%= cardtype %>"
type="text/css">
where the variable cardtype has the value of either standard, gold or platinum, depending on the visitor's credit card type.
If you are already using style sheets, you are probably using a static text file with a .CSS file extension. Sometimes you may want to change the look of a page based on dynamic content. One way to do this is by dynamically producing the cascading style sheet.
A Web page can specify to use a particular style sheet via the link tag. The link tag contains a number of attributes. For starters, the rel attribute should contain the value "stylesheet", while the type attribute of the link tag should be set to "text/css". Finally, the href attribute must point to a file containing the style rules. In using this href attribute you can make your stylesheets dynamic, since the href attribute can point to any file that returns the rules in text format, even an ASP page! A querystring parameter can be used to pass along dynamic values, which can be used to determine the content of the style sheet rules. The end result? Dynamic style sheets!
Why would you want to use dynamic style sheets? A simple example: Bank X uses ASP to produce pages where customers can view information about their credit card accounts. Bank X has three types of cards: standard, gold and platinum. One ASP page can be used to display transaction information for all three account types, and it can pass the type of card to a style sheet generating ASP-page; the style sheet generated would be appropriate to the user's card type.
So, let's look at some code! First, here's what the style sheet link tag looks like:
<link rel="stylesheet"
href="dynastyle.asp?cardtype=<%= cardtype %>"
type="text/css">
where the variable cardtype has the value of either standard, gold or platinum, depending on the visitor's credit card type.
Creating Dynamic Cascading Style Sheets with ASP 评论
