Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Dynamic CSS

Reply
Thread Tools

Dynamic CSS

 
 
JWL
Guest
Posts: n/a
 
      06-29-2006
Hi

I need to create a bunch of sites with slightly dynamic CSS. Basically,
all the image paths in the CSS need to be dynamic, depending on the
values of certain ASP variables.

I can think of 3 ways to do this:

1. Write a script to create a semi-dynamic CSS file, which will be run
whenever we need to make changes to the ASP variables controlling the
image paths.

2. Have an ASP script generate the CSS on the fly:

<link href="dynamiccss.asp" rel="stylesheet" type="text/css">

3. Put all static CSS in a normal CSS file, and have a special dynamic
style sheet for only those rules that require variability. We could
either use method 2 above to generate a second style sheet, or place
dynamic rules directly in the actual asp pages.

I'm not sure what to do. (1) has the disadvantage that the CSS is not
truly dynamic. (2)... well, I'm not sure if (a) this is legal by W3C
standards and whether there's a performance hit involved. (3) has the
disadvantage that it places rules for the same elements in different
locations, which could lead to confusion.

Is there a generally accepted way to solve this problem?
 
Reply With Quote
 
 
 
 
Mike Brind
Guest
Posts: n/a
 
      06-29-2006

JWL wrote:
> Hi
>
> I need to create a bunch of sites with slightly dynamic CSS. Basically,
> all the image paths in the CSS need to be dynamic, depending on the
> values of certain ASP variables.
>
> I can think of 3 ways to do this:
>
> 1. Write a script to create a semi-dynamic CSS file, which will be run
> whenever we need to make changes to the ASP variables controlling the
> image paths.
>
> 2. Have an ASP script generate the CSS on the fly:
>
> <link href="dynamiccss.asp" rel="stylesheet" type="text/css">
>
> 3. Put all static CSS in a normal CSS file, and have a special dynamic
> style sheet for only those rules that require variability. We could
> either use method 2 above to generate a second style sheet, or place
> dynamic rules directly in the actual asp pages.
>
> I'm not sure what to do. (1) has the disadvantage that the CSS is not
> truly dynamic. (2)... well, I'm not sure if (a) this is legal by W3C
> standards and whether there's a performance hit involved. (3) has the
> disadvantage that it places rules for the same elements in different
> locations, which could lead to confusion.
>
> Is there a generally accepted way to solve this problem?


The generally accepted way is to do whatever works best for you with
the minimum amount of work. Another alternative is to dynamically
generate the <link href="style.css" rel="stylesheet" type="text/css">
tag using a SELECT CASE, and have a number of hardcoded style sheets to
link to.

With regard to your points and comments on them:

1. So what if it's not truly dynamic (whatever that means)? If it
works, it works.
2. The browser has no idea what generated the CSS file. It either
validates, or it doesn't. However, generating a style sheet every time
a page is requested seems unnecessary.
3. You're right - you are overcomplicating things.

--
Mike Brind

 
Reply With Quote
 
 
 
 
dp
Guest
Posts: n/a
 
      07-11-2006
JWL wrote:
> Hi
>
> I need to create a bunch of sites with slightly dynamic CSS.
> Basically, all the image paths in the CSS need to be dynamic,
> depending on the values of certain ASP variables.
>
> I can think of 3 ways to do this:
>
> 1. Write a script to create a semi-dynamic CSS file, which will be run
> whenever we need to make changes to the ASP variables controlling the
> image paths.
>
> 2. Have an ASP script generate the CSS on the fly:
>
> <link href="dynamiccss.asp" rel="stylesheet" type="text/css">
>
> 3. Put all static CSS in a normal CSS file, and have a special dynamic
> style sheet for only those rules that require variability. We could
> either use method 2 above to generate a second style sheet, or place
> dynamic rules directly in the actual asp pages.
>
> I'm not sure what to do. (1) has the disadvantage that the CSS is not
> truly dynamic. (2)... well, I'm not sure if (a) this is legal by W3C
> standards and whether there's a performance hit involved. (3) has the
> disadvantage that it places rules for the same elements in different
> locations, which could lead to confusion.
>
> Is there a generally accepted way to solve this problem?


You don't have to use the .css extension for an included style sheet. You
can acutally use a .asp extension and intersperse asp and css much the same
way you would if you had html interspersed within an asp page. You just have
to set the content type of the .asp css file to text/css.

An example of what's in an .asp file linked to instead of a .css file is...
THE HTML
------------------
<link rel="stylesheet" type="text/css" href="/stylesheet.asp?margin=10">


THE stylesheet.asp FILE
---------------------------------
<%
Response.ContentType="text/css"
Dim strImageMargin
strImageMargin = Request.QueryString("margin")
%>

img {margin:<%=Trim(strImageMargin)%>px;

--
dp


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Layout question - how to duplicate a table layout with CSS Eric ASP .Net 4 12-24-2004 04:54 PM
confused - html validates, css validates but validate css from the html causes errors Titus A Ducksass - AKA broken-record HTML 6 11-15-2004 12:59 PM
Set CSS property equal to another CSS property? Noozer HTML 10 10-13-2004 09:20 PM
Is there a way to set the a CSS property to be explicitly the same as another CSS property? Joshua Beall HTML 1 12-10-2003 07:21 PM
print.css and screen.css tom watson HTML 1 09-09-2003 02:48 PM



Advertisments