Forum Moderators: not2easy

Message Too Old, No Replies

Multiple CSS Inheritance

Can it be done?

         

cmarshall

1:45 pm on Jan 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Folks,

I have a way of specifying date-sensitive CSS. I apply a series of classes to my <body> element that correspond to the day, like so:

<body class="date_h_08 date_wd_Mon date_d_15 date_m_01 date_y_2007 date_dm_15_01 date_my_01_2007 date_dmy_15_01_2007">

This way, I can specify a special "heart" background on Valentines Day, like so:

body.date_dm_14_02 div#maincontent
{
background-image: url(mushy_heart_background.gif);
}

Now, as you can see, that <body> element is just a tad long-winded. I had to construct a series of styles in order to give designers using my sites as many choices as possible.

Here's my question: Is it possible to have specific CSS keyed to more than one "container class"? For example, can I have something like this:

body.date_d_14 body.date_m_02 div#maincontent
{
background-image: url(mushy_heart_background.gif);
}

I can try testing stuff out at some later time (I can't spend much time on it right now). However, there are some real heavyweights on this thread, so I figured I'd ask first.

DUH: That's "Inheritance."

cmarshall

3:23 pm on Jan 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<takes off glasses and rubs eyes>

I would SWEAR that I had mistyped "Inheritance" as "Inhertiance."

<throws bottle in trash, holding hand to breast, muttering>

Fotiman

3:46 pm on Jan 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Interesting idea (the way you've applied those classes). But unfortunately, no, there isn't a way to do what you're asking, simply because the CSS selector syntax doesn't support it.

cmarshall

4:06 pm on Jan 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's kinda what I thought.

The technique allows for "seasonal" themes. You could have varying shades of green that get greener in April and May, then gradually change to yellow by October, turning white for the winter months, etc.

Lot of CSS, but some folks won't mind doing it.

Ingolemo

4:42 pm on Jan 15, 2007 (gmt 0)

10+ Year Member



Do you mean selecting multiple classes? If so;
body.date_d_14.date_m_02 div#maincontent {
background-image: url(mushy_heart_background.gif);
}

cmarshall

4:49 pm on Jan 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you mean selecting multiple classes? If so;
body.date_d_14.date_m_02 div#maincontent {
background-image: url(mushy_heart_background.gif);
}

That may be what I am looking for. I didn't know if it were possible. I would also need to test across several browsers.

The idea is to remove the need for date_dm_XX_XX, and replace it with a class that only becomes active when a single container has two classnames that correspond to the same date.

Ingolemo

5:12 pm on Jan 15, 2007 (gmt 0)

10+ Year Member



I know Firefox, Opera, and IE7 support it. IE6 doesn't (it only recognizes the last class specified in the rule so there's room for graceful degradation there).