tags:

views:

70

answers:

4

For example I have this css class:

.class{
   background:#FFF; 
   border:1px solid #ccc
}

And I have this HTML structure:

<ul class="list">
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
</ul>

And I would like to use the .class on the list. li elements without adding the class="class" to the <li>'s or rewriting the whole class for the <li>'s.

Something like:

.list li{
   .class
} 

Is this possible somehow?

+1  A: 

you know the easier way would be

.list li, .class {
      whatever css
}
Kasumi
That's not what the OP is asking.
Jason McCreary
it gets the job done =P exactly as he wants... but no as everyone mentioned, it is not possible...
Kasumi
+3  A: 

You can let some css be applied to different css selectors with comma ,. So your example would be:

.class, .list li {
   background:#FFF; 
   border:1px solid #ccc
}
lasseespeholt
This is the standard way of doing it. However, there are frameworks as noted by **Alan**. Check out http://lesscss.org/, this is probably more of what you wanted. Unfortunately it is not part of CSS at this time.
Jason McCreary
+1  A: 

No, unfortunately that doesn't work. Flex has that concept with

.myClass {
  styleName: "myStyleName";
}

But CSS doesn't work that way. CSS also needs nested selectors, but I wouldn't want to hang from a rope until that happened.

Robusto
+1  A: 

It is not possible using plain CSS. However, CSS frameworks exist which have these functionalities.

Alan Haggai Alavi