Forum Moderators: not2easy

Message Too Old, No Replies

Can I define a class by reference to an other?

         

Hurcule

11:21 am on Apr 2, 2009 (gmt 0)

10+ Year Member



Is it possible to define a class by reference to an earlier defined one?

Something along the lines of: -

.foo {bar}

Where bar has been defined earlier?

I’m attempting to maximise the presentational control in my master external style sheet in a php environment where the class of some of the data from includes might be different dependent on the page that is calling it.

foo and bar would both be defined in the external CSS and, when necessary, the foo style would be replaced by the bar style in the header of the calling page.

Clearly I can achieve this by redefining foo in every page it is necessary but that removes control from the master CSS file.

There is probably an easier way of doing this that I’m missing!

Thanks

simonuk

1:48 pm on Apr 2, 2009 (gmt 0)

10+ Year Member



I may getting the wrong end of the stick but you can have multiple classes on one element so you could have:

<p class="foo">Hello</p>
Which has one style but then

<p class="foo boo">Hello</p>
Which would override the first style.

Equally you could go ID + class on one element but it sounds like you'd be wanting to repeat the styles across the page so this method would be better.

rocknbil

3:22 pm on Apr 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about

.foo { color:#ff0000; }
#specific-page .foo { color: #0000ff; }

<h3 class="foo">Foo</h3> <!-- I love redheads -->

then

<body id="specific-page">

<h3 class="foo">Foo</h3> <!-- blueheads are ok, I guess -->

Hurcule

4:00 pm on Apr 2, 2009 (gmt 0)

10+ Year Member



Thanks for the quick reply Simon, I’m afraid my powers of explanation have let me down!

It’s a relatively simple business website with 14 major product groups but most of the website is structured around over 20 market sectors.

Each market sector page has a list of these product groups at the bottom with links and this is simply achieved by a php include.

However in many markets one or two products are not relevant and this presentation has caused some confusion that we want to resolve by de-emphasising the presentation of the irrelevant product in the list.

At the moment the style associated with the list is called “prodlist” I though a simple solution could be to create 14 identical styles “prodlist1 prodlist2 .... prodlist14” plus “prodlistdemph”.

Then, on those pages where, say, product group 7 needs to be de-emphasised to redefine “prodlist7” by making it equal to “prodlistdemph” in the head of the page.

I just don’t know how to define a style by reference to another.

Of course, I can achieve the same effect by hard coding the redefinition in all the appropriate pages and not using "prodlistdemph" but that structure creates work for changes and we are continually tweaking the presentation.

Hurcule

4:46 pm on Apr 2, 2009 (gmt 0)

10+ Year Member



rocknbil – thanks for that, made me feel a little foolish. It brings everything into the master style sheet.

My idea had caused me to ignore it as, with over 20 market sector pages with a couple of de-emphasised on each meant over 50 definitions, but of course, it is really only one definition of a list of 50 elements.

I guess that creating elegant designs based on nonexistent functionality is a good way to waste everyone’s time!

rocknbil

9:55 pm on Apr 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not at all, welcome aboard. Sometimes you have to see it laid out to see the beauty of simplicity. I've asked my fair share of "dumb q's. :-P