Bruce,

>I have a question. I am working on our school's websites and rather than
>have 12 different style sheets, I would like to have one style sheet that
>has three classes where the background-color attribute is dynamic. So how
>would I go about doing this? Now I can create a css.cfm page and load the
>colors into the database, making sure that the proper school ID is
>associated with their respective colors, but I thought that I might be able
>to use the .css page instead.

Among the many other options, another method that would not involve using
CFML to generate the CSS is this:

* Create a base CSS which has all the CSS rules you want in it.
* For each set of color variations, create a new CSS file. In this you'll
want to place CSS rules to just overwrite the colors you need overwritten.
* Load the base CSS file first
* Then right after, load the correct CSS file that overwrites the colors for
that style.

Using this method all the core CSS rules (that set position, font styling,
etc) are in one place. The additional CSS files you contain would just
contain rules to overwrite the colors.

For example:
---- default.css ----
h1 {
        margin: 0px;
        font: Arial;
        border-bottom: 1px solid #cccccc;
}

--- style_red.css ---
h1 {
        border-color: #ff0000;
}

--- style_green.css ---
h1 {
        border-color: #00ff00;
}

--- style_blue.css ---
h1 {
        border-color: #0000ff;
}

Now if you load the CSS files like:

--- Example 1 ---
<!---// load default styles //--->
<link href="default.css" rel="stylesheet" type="text/css" />

<h1>Grey Border</h1>

--- Example 2 ---
<!---// load default styles //--->
<link href="default.css" rel="stylesheet" type="text/css" />
<!---// load "red" styles //--->
<link href="style_red.css" rel="stylesheet" type="text/css" />

<h1>Red Border</h1>

Depending on which "style_*.css" file you load, you can change just the key
aspects of the CSS to support style.

The nice thing about this method is you don't have to push another file
through the CFML engine. If you push CSS files through the CFML engine, that
means for every page request a browser is going to need at least 2 CF
threads.

You could create a script to generate static versions of the style_*.css
files if you wanted to generate those files automatically based upon data in
the database.

-Dan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:288109
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to