2

私は、クラシック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" />

ASPCSSページ

<%
   dark_color = "navy" 
%>

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

2 に答える 2

2

ここで欠けている要素はコンテンツタイプでした。従来のASPページはtext/HTMLデフォルトで提供されるため、スタイルシートを期待するブラウザは混乱しますtext/css

コンテンツタイプの変更は次のように行われます。

Response.ContentType = "text/css"

MSDNドキュメント

于 2013-02-22T16:47:42.143 に答える
0
    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 %>;
} 
于 2014-01-25T16:23:37.427 に答える