+ 2
I still don't understand the difference between I'd and class
4 Réponses
+ 3
ID should be used to change the style of a single element, whereas a class can be applied to miltiple elements to apply the same style defined in the css. You can apply the same id to multiple classes to have the same effect, and likewise you can apply a class to a single element to function like an ID but that wouldn't make sense.
There is a distinction between the 2 to help make the code more readable. If you see an element with an ID you know that only that one element is going to be changing so you can change it's css and not worry about any other elements being affected. Likewise if you look to change a class, beware that you'll be changing the style of other elements as well.
Basically if you want to change the style of more than one element, create a class for it, if not use ID. It will make it easier for example to change the colour of the text of multiple elements on the screen all at the same time as opposed to changing the css for each element ID 1 at a time
+ 3
I'd can be used once for each element
Class can be called multiple times
0
Id can only be used once in the whole HTML document, whereas class can be used multiple times.
0
That's right. You can apply multiple classes to the same element simply by seperating the class names with a space. You can't do that with IDs.
E.g. id="error" class="class1 class2 class3"