... because sometimes you see a class used in multiple different tags, and this helps avoid surprises.
Well, a class is used to define common properties of an element, so you shouldn't have surprises. That's part of a good design. If you want to have two buttons, both with an orange 2px *thick* border, black background, white letters BUT with different widths, then you should write an "extra" class for the wider button. So, your markup would look like this:
<input type="button" class="genericBtn" value="button 1" />
<input type="button class="genericBtn widerBtn" value="button 2" />
Your CSS would look like this:
.genericBtn {
background: #000;
border: solid 2px #fc0; /*If I remember well, this is the code for orange*/
color: #fff;
}
.widerBtn {
width: 400px;
}
Notice that in button 2 you're combining two classes. That should produce the results you want.
Also, it's of good practice to use descriptive names for your classes (notice in my example "genericBtn"), that will help you a big time.
actually you can have multi elements with the same Id.
Yes, you could have multiple elements with the same ID, and if you ever find a page whose source code shows various elements with the same ID, you should encourage whoever wrote the code of that page to grab his/her books again and go back to HTML 101. Multiple elements with the same ID in a single page is of bad practice and frowned upon. IDs should be unique in a single page... that's why they're IDs. To style multiple element in a page with the same attributes there's nothing better than classes.
Now, you do use "div.navigation" or "div#navigation" when you want to force an element to be styled the way you want. I'll try to explain:
Let's say you're trying to style the navigation bar of an existing theme. The original definition reads like this:
.navbar {
background: #000 !important;
...
...
}
But you don't want it to have a black background; you want it to be red, but since you can't modify the original CSS, you write your new definition:
.navbar {background: #f00;}
You test it, but the background is still black. Then you say "wait, I need to add the '!important' rule so my definition takes precedence." You go back to your code and rewrite it like this:
.navbar {background: #f00 !important;}
You test it again, but... bummer! the background is still black. How to solve this? Well, you do it like this:
'
div.navbar {background: #f00 !important;}
'
NOW your navbar should have a red background.
I hope this helps.