tags:

views:

56

answers:

6

Hi,

I have a css class like:

.foo {
  background-color: red;
}

then I have a class specified for a list:

.list1 li {
  background-color: tan;
}

is it possible to set one style class to just point to another? Something like:

.list1 li {
  .foo;
}

not sure how to articulate that - I just want the .list li style to be whatever I define for the .foo class.

Thanks

A: 

Inheritance is, as far as I know, not supported in CSS (2.1 at least)

Lars Mæhlum
+6  A: 

You can use selector grouping:

.foo, .list1 li { 
  background-color: red; 
} 
ChrisW
Ah neat that actually works perfect for my case, thanks all.
+1  A: 

Afaik, this isn't possible (yet) I hope it will be in the future. I always just copy+paste whatever I want to be the same into the desired selector or put the selector names one after another:

.foo,
.li,
.whatever
{styles}

Maybe someone else has another suggestion.

Kyle Sevenoaks
A: 

No you can't but you override it using naming differnt classes for example

.foo { background-color: red; }

.list1 li { background-color: tan; }

class ="list1 foo"
Salil
+1  A: 

No. The best you can do with "native CSS" is to use a multiple selector:

.foo, .list1 li {
   ...
}

Otherwise there are preprocessors that can help with this such as SASS.

RoToRa
I believe you mean `.list1` instead of `list1`; the latter is not an element selector, so it must be a class selector.
Robusto
Oops. Yes that was a typo.
RoToRa
+3  A: 

Not with any syntax like that (and don't confuse a "class" (an HTML term) with a "class selector" or a "rule-set").

Your options are multiple classes, grouping selectors or preprocessing.

David Dorward