tags:

views:

31

answers:

2

I have a slider that's marked up like so:

<div class="slider wide">
//slider html in here
</div>

And another marked up like so:

<div class="slider narrow">
//slider html in here
</div>

Is it possible to reference each of these like this in my CSS file by in a way concatenating the class names:

.slider.wide { //css specific to the wide slider goes here }
.slider.narrow { //css specific to the wide slider goes here }
+4  A: 

No, you make three classes .slider, where you put common slider css, and .narrow where you put narrow slider specific css, and .wide where you put wide slider specific css.

.slider { //css common among all sliders goes here }
.wide { //css specific to the wide slider goes here }
.narrow { //css specific to the narrow slider goes here }
aularon
Balls, I was too slow :D +1
ILMV
@ILMV haha, me too...
captaintokyo
Ok, maybe my example is a bit too simplistic. I'm actually looking at someone else's code at the moment and trying to work it out.I would normally follow the example you've shown but best practice aside, should it work? Is it invalid CSS?
Steph
It seems to be valid: http://jsfiddle.net/XQ9w9/ I tested with firefox, don't know if some other browser has a problem matching that selector.
aularon
+1  A: 

Yes, .slider.narrow is valid. It's not exactly concatenating the class names, it's making two different class selectors and applying them to the same element. So .narrow.slider is also valid and will match the same elements.

The problem with using multiple class selectors against a single element is that is doesn't work in IE6. This browser will ignore all but the last class selector. So to support that browser you typically end up using something like class="slider wide-slider".

bobince
Thanks for this - I was afraid that browser support in IE6 (or indeed any browser) would be an issue. Cheers!
Steph