【问题标题】:Dynamic CSS page using Classic ASP使用经典 ASP 的动态 CSS 页面
【发布时间】:2013-02-22 16:18:38
【问题描述】:

我一直在试图弄清楚如何使用经典的 asp 引入动态 CSS 样式表。我已经阅读了很多关于这个主题的教程,但我似乎无法正确地理解它。他们中的许多人似乎暗示只需更改为 styles.asp 或 .aspx 并使用标准样式表链接引用它就可以了,但我没有得到那个结果。

http://www.4guysfromrolla.com/webtech/tips/t071201-1.shtml

我想要实现的是能够将工作中的 CMS 中的服务器端变量提取到我的样式表中。我意识到 SASS 和 LESS 存在并且可能能够适应,但我只是想找到一种简单的方法来使用 asp 变量并将它们拉到我的样式表中。我不是非常精通 ASP,所以您可以提供的任何帮助都会有所帮助。

编辑:我更新了下面的代码以反映工作代码。

HTML

<link rel="stylesheet" href="<% = TemplatePath %>css/styles.asp" type="text/css" />

ASP CSS 页面

<%
   dark_color = "navy" 
%>

<% Response.ContentType = "text/css" %>
<style type="text/css">
   h2 { color: <%= dark_color %> }
</style>

【问题讨论】:

  • 我需要查看代码才能提供建议。
  • 他们需要在样式表中吗?它们可以是内联样式还是标题中的样式标签?
  • @Pete 理想情况下,我希望它们出现在样式表中。我希望将它大量集成到我现有的样式表中,以便我可以从 CMS 中提取动态颜色并在 CSS 中更改和操作它们。为了清楚起见,我只是尽量不要用额外的细节使我的问题过于复杂。
  • 尝试在 ASP 页面中设置 Response.ContentType = "text/css" 看看是否有帮助。
  • @ChrisNielsen 太棒了,这看起来就是我的问题所在。您想在下面添加它作为答案,我可以为您提供解决方案吗?

标签: css variables asp-classic


【解决方案1】:

这里缺少的成分是内容类型。默认情况下,经典 ASP 页面以 text/HTML 提供服务,这会使期望样式表为 text/css 的浏览器感到困惑。

更改内容类型如下:

Response.ContentType = "text/css"

MSDN documentation

【讨论】:

    【解决方案2】:
        you could use global variables like Application and session which are accessible across overall application.
    
        here are the codes for your reference -
    
        my asp page named asp_1.asp
    
        <!DOCTYPE html>
        <html>
        <head>
    
             <link rel="stylesheet" type="text/css" href="dynastyle.asp">
        </head>
        <body>
        <%
        Set MyBrow=Server.CreateObject("MSWC.BrowserType")
    
        Application("myfontcolor") = "#ff0000"
    
        %>
    
        <table border="0" width="100%">
        <tr>
        <th>Client OS</th><th><%=MyBrow.platform%></th>
        </tr><tr>
        <td >Web Browser</td><td ><%=MyBrow.browser%></td>
        </tr><tr>
        <td>Browser version</td><td><%=MyBrow.version%></td>
        </tr><tr>
        <td>Frame support?</td><td><%=MyBrow.frames%></td>
        </tr><tr>
        <td>Table support?</td><td><%=MyBrow.tables%></td>
        </tr><tr>
        <td>Sound support?</td><td><%=MyBrow.backgroundsounds%></td>
        </tr><tr>
        <td>Cookies support?</td><td><%=MyBrow.cookies%></td>
        </tr><tr>
        <td>VBScript support?</td><td><%=MyBrow.vbscript%></td>
        </tr><tr>
        <td>JavaScript support?</td><td><%=MyBrow.javascript%></td>
        </tr>
        </table>
    
        </body>
        </html> 
    
        here i displayed simple HTML table to display browsers capability. you could use any element as per your requirement.
    
    another steps towards the solution is to create asp page with dynamic css named dynastyle.asp. here is the code for same -
    
    <% Response.ContentType = "text/css" %>
    <%
    DIM fontColor
    **fontColor =Application("myfontcolor")**
    %>
    
        table
    
    {
        background-color: <%= fontColor %>;
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      相关资源
      最近更新 更多