tags:

views:

84

answers:

6
<div id="SideBar" class="sidebar mainbar">

I've just seen this in a .aspx file. Is this valid? Can someone point me in the right direction to learn what this does. I'm assuming its valid, but I'm not finding it in the css file. I am finding sidebar defined as a class, but not mainbar.

Thanks in advance,

Randy

+1  A: 

Yes this is perfectly valid. An element can be styled by multiple classes.

See this reference and this one which touches on which one takes precedence for duplicate style attributes.

AdaTheDev
Thanks for the quick response and the references...
Iceman
+4  A: 

This div just has two classes, which means it will get the properties defined under .sidebar as well as those under .mainbar

Wim
Thanks for the quick response...
Iceman
+1  A: 

CSS Tricks has a few other CSS tricks including having two classes.

Copy/Pasting the trick from the above site:

Usually attributes are assigned just one class, but this doesn't mean that that's all you're allowed. In reality, you can assign as many classes as you like!

Using these two classes together (separated by a space, not with a comma) means that the paragraph calls up the rules assigned to both text and side. If any rules overlap between the two classes then the class which is below the other in the CSS document will take precedence.

Ezweb
Thanks to everyone for the quick responses and the references. Need to look into referencing a class via javascript.
Iceman
+3  A: 

As for mainbar not showing up in your CSS file, sometimes developers assign classes to elements and then reference those classes in javascript.

Andy Gaskell
Or not at all, developers do strange things sometimes... ;-)
Wim
That is very true
Andy Gaskell
+5  A: 

Sure, you can have an element implement as many css classes as you like. If there is no class defined in the CSS files it is possible that either:

  1. The additional css classes have been removed from the styles sheets and the .aspx pages have not been refactored to match.
  2. The css class is been used to identify the element(s) via javascript or some other scripting language.
Owen
or 3. that it's used when read by a proprietary processor rather than a browser. Or 4. that it's a marker for future use. Remember that a class is for element categorization - it's not, per se, a CSS property. It just that binding CSS to it is by far it's most common use.
Alohci
+1 Alohci for the additional info
Owen
A: 

Beware of IE6 if someday you try to style an element using more than one class, it doesn't work like intended.

No problem with id+class (like #anid.class ) or two selectors like .classA and then .classB but no .classA.classB

Felipe Alsacreations