- 1
The basic difference between Id and class it that, an ID can be applied to only single type of elements no matter how many times you apply or how many ids you create but in slight edge class is same as id but can be applied to different types of elements Am I Right?
4 Réponses
+ 1
Actually I believe ID is only for a specific element. Each element can have only one ID, and each page can have only one element with that ID. So you couldn't have 2 elements with same ID.
A class is like a global rule, multiple elements can share the same class and will be styled accordingly.
- 1
<h1 id="sd">
<p id="sd">
both works...
<h1 id="s d"> not allowed.
<h1 class="s d">
<p class="s"> both allowed and both r in 's' class and h1 is in 's' class as well as in 'd' class...
- 1
you mean to say, a single tag type cannot have different IDs...wherever I use it in the HTML structure
- 1
"Id" is to identify an element and being used in header and footer mainly, while "class" is to identify a group of elements and also yes you are right