set a class to another class in a CSS stylesheet

C

Ciaran

Hi is it possible to set a class to another class in a stylesheet
file? As circumstance would have it I need to do something like this:

..class1{ color:#ccc;}

..class2{ class:class1; width:200px;}

It kind of goes agains the whole "cascading" idea so I'm not sure if
its possible. if it is, can someone post the syntax?

Thanks
Ciaran
 
R

Rik

Ciaran said:
Hi is it possible to set a class to another class in a stylesheet
file? As circumstance would have it I need to do something like this:

.class1{ color:#ccc;}

.class2{ class:class1; width:200px;}

It kind of goes agains the whole "cascading" idea so I'm not sure if
its possible. if it is, can someone post the syntax?

Are you sure you don't simply mean:

..class1.class2{width:200px;}
 
C

Ciaran

Ha ha no I didnt mean that but I think I've figured out another way
around it anyway. Thanks for the reply Rik!
 
J

Jukka K. Korpela

Scripsit Ciaran:
Hi is it possible to set a class to another class in a stylesheet
file?

No. Classes don't exist in CSS at all. They exist in markup; CSS just refers
to them.
As circumstance would have it I need to do something like this:

.class1{ color:#ccc;}

.class2{ class:class1; width:200px;}

No, you don't need to do such things. You should not set color without
setting background, and you should not set widths in pixels excep in special
occasions.

You might find use for things like

..class1, .class2 { color: #ccc; background: white; }

..class2 { width: 15em; }

(with more sensible class names of course).
It kind of goes agains the whole "cascading" idea

This has absolutely nothing to do with the cascade, which is the most
misunderstood concept in the Whole Wide Web.
 
J

Jonathan N. Little

Ciaran said:
Hi is it possible to set a class to another class in a stylesheet
file? As circumstance would have it I need to do something like this:

.class1{ color:#ccc;}

.class2{ class:class1; width:200px;}

It kind of goes agains the whole "cascading" idea so I'm not sure if
its possible. if it is, can someone post the syntax?

No but your can use more than one class

..sample { color: #fff; background-color: #500; }

..wide { width: 1000px; }
..skinny { width: 100px; }


<div class="sample wide">A very wide block</div>
<div class="sample skinny">A very narrow block</div>
 
B

Bernhard Sturm

Ciaran said:
Hi is it possible to set a class to another class in a stylesheet
file? As circumstance would have it I need to do something like this:

.class1{ color:#ccc;}

.class2{ class:class1; width:200px;}

It kind of goes agains the whole "cascading" idea so I'm not sure if
its possible. if it is, can someone post the syntax?

why not:

..class1, .class2 { color:#ccc;}

..class2{width:200px;}

should do the trick...
 
D

dorayme

It kind of goes agains the whole "cascading" idea

This has absolutely nothing to do with the cascade, which is the most
misunderstood concept in the Whole Wide Web.[/QUOTE]

In my own opinion, I have the best misunderstanding of it, far
higher than any earthling I know.
 
C

Ciaran

Hi guys thanks for the replies on this. There's a complicated reason
behind it but what I was trying to do was define a new class that has
all the same properties of some old class plus a few more. But I
needed to do it without changing the html - just CSS. I've kind of
given up on the idea now but it would still be interesting to know if
it's possible to use classes like that.
 
M

mbstevens

Ciaran said:
Hi guys thanks for the replies on this. There's a complicated reason
behind it but what I was trying to do was define a new class that has
all the same properties of some old class plus a few more. But I
needed to do it without changing the html - just CSS. I've kind of
given up on the idea now but it would still be interesting to know if
it's possible to use classes like that.
Sure. Just generate your (X)HTML and CSS server side and make any
changes you want before sending the page.

But there are also all sorts of precedence and cascade rules that can be
applied, and your question leaves me unsure which kind of thing you are
imagining. Can you be more specific?

In the meantime, Google "CSS precedence" and "CSS cascade".
 
D

dorayme

"Ciaran said:
Hi guys thanks for the replies on this.

On what? Please quote stuff otherwise people not on Google will
not see what you are talking about. The people likely best able
to help you will not be using Google at all.
There's a complicated reason
behind it but what I was trying to do was define a new class that has
all the same properties of some old class plus a few more. But I
needed to do it without changing the html - just CSS.

But the one reply I was able to recover from my newsreader gave
you a method. By Bernard Sturm. That was just about the css.
I've kind of
given up on the idea now but it would still be interesting to know if
it's possible to use classes like that.

?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top