Click to See Complete Forum and Search --> : Concatenate Classes...


bubbisthedog
10-18-2005, 03:42 PM
Hello.

I've learned that you can concatenate CSS classes with the "&" (ampersand) operator, and was wondering if this was a *proper* way to utilize CSS. Are there detriments? I couldn't find any documentation on this.

Just curious...

Thanks a lot,

bubbis

Kravvitz
10-18-2005, 04:11 PM
Where did you learn that?

As far as I know, "&" is not a valid CSS selector combinator.

bubbisthedog
10-18-2005, 04:20 PM
Hi, Kravvitz. If you do this:

<style type=text/css>
.c1 {font-weight:bold}
.c2 {text-decoration:italic}
</style>

...and then this:

<div class="c1 & c2">bob</div>

you get bob. Was I not supposed to figure this out? HAHAHAHA

Regards,

bubbis

NogDog
10-18-2005, 04:37 PM
Actually what is happening is that you are trying to assign three class names: "c1", "&", and "c2" (the separator for a list of classes is any whitespace character). Since "&" is not defined (and by definition cannot be since "&" is an invalid character for a CSS selector), the other two valid classes are being assigned to the element. In other words, you'll get the same effect with:

<div class="c1 c2">bob</div>

Kravvitz
10-18-2005, 04:37 PM
Yes, in CSS2 an element can belong to more than one class -- it's a space delimited list.

The "&" is being ignored. Try it without the "&".

bubbisthedog
10-19-2005, 07:45 AM
So then the ampersand wasn't a concatenation operator after all... Great to know. Thanks a lot for the responses, nogdog and Kravvitz!

Regards,

bubbis