In the past, we utilized a straightforward .aspx page for our "dynamic" CSS implementation.
While we have a core CSS set in place, there is a need to present various site sections in distinct colors to enhance branding and assist users in navigating different areas of the site.
The key task here is to manage response encoding:
private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "text/css";
}
Next, modify the front-end code as follows:
<%
string strSiteArea = this.Page.Request.QueryString["sitearea"];
string strCustomStyles = this.Page.Request.QueryString["customcssstyles"];
string extralightcolour = "";
string lightcolour = "";
string normalcolour = "";
string darkcolour = "";
string customcolour = "";
switch (strSiteArea)
{
case "miscellaneous":
extralightcolour = "#F2F2F2";
lightcolour = "#E6E6E6";
normalcolour = "#999999";
darkcolour = "#666666";
break;
case "pressoffice":
extralightcolour = "#F0F4F7";
lightcolour = "#E2E9EE";
normalcolour = "#6D8DA8";
darkcolour = "#5C768D";
break;
// additional cases can be added
}
%>
h1{color: <%= darkcolour %>;font-family: Arial;padding-left: 0;margin-left: 0;}
h2{color: <%= darkcolour %>;font-family: Arial;font-size: 1.2em;font-weight: bold;margin-bottom: 0;padding-bottom: 0;}
h3{color: <%= darkcolour %>;font-size: 1.1em;font-weight:normal;margin-bottom: 0;}
h4{color: <%= darkcolour %>;margin-bottom: 0;font-size: 1.1em;font-weight:normal;font-style:italic;}
.backgroundheading{margin: 0 0 0 0;background-color: <%= normalcolour %>;color: #FFF;font-weight: bold;font-family: Arial;font-size: 1.0em;text-align: left;padding: 3px 5px 3px 5px;}
.backgroundheadinglight{margin: 0 0 0 0;background-color: <%= lightcolour %>;color: #000;font-weight: bold;font-family: Arial;font-size: 1.0em;text-align: left;padding: 3px 5px 3px 5px;}
.backgroundheadingdark{margin: 0 0 0 0;background-color: <%= darkcolour %>;color: #FFF;font-weight: bold;font-family: Arial;font-size: 1.0em;text-align: left;padding: 3px 5px 3px 5px;}
.background{margin: 0 0 0 0;background-color: <%= normalcolour %>;text-align: left;padding: 3px 5px 1px 5px;}
.backgroundlight{margin: 0 0 0 0;background-color: <%= lightcolour %>;text-align: left;padding: 3px 5px 1px 5px;}
.backgrounddark{margin: 0 0 0 0;background-color: <%= darkcolour %>;text-align:left;padding: 3px 5px 1px 5px;}
.backgroundcolorextralight{background-color: <%= extralightcolour %>;}
To apply the CSS on a page, use the following snippet:
<link rel="stylesheet" href="/CSS/GenerateCss.aspx?siteArea=pressoffice" />
This approach allowed us to implement multiple color schemes while maintaining a consistent CSS style set, making it easy to adjust page appearance based on the provided query string.