473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamic CSS

JWL
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?
Jun 29 '06 #1
2 6335

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

Jun 29 '06 #2
dp
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
Jul 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October...
1
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
7
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.