id or class?
- Started
- Last post
- 6 Responses
- Shepstar15
I have a simple question but still not sure:
If i use id then I would use class inside the id tag
but can you use two id and one class tag inside? Or would that be stupid?
For example
Normally
<div id="outside">
<div class="inside">
</div>
</div>is this correct?
<div id="outside">
<div id="inside">
<div class="test">
</div>
</div>
</div>would that be ok or shouldn't you use to div ids ?
- BattleAxe0
well, id is meant to be a unique identifier something you would only use once , class is if you want to apply it to more thatn one tag ,
- neverblink0
quick anwser:
You can use classes or id's inside eachother. But there can only be ONE element with a specific ID, where there can be MANY elements with the same CLASS.example:
<div id="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
- Stugoo0
id is for one use on the page only,
class is for multiple uses,it doesn't matter how you nest them
- jonatne0
IDs are meant to name elements.
The idea is that the ID is a 'unique identifier' (BattleAxe) and as they have all said, each ID name can only be used once. Depending on what element you are giving and ID too, that element can be accessed via a #elementname anchor.Classes are meant to 'classify' elements. They should be used to say what type of a certain element is or what group it should fall into. You can also have multiple classes on one element. (ex. class="red hidden important" )
- Shepstar150
thanks that helped me.