+ 1
What is the difference between id and class on CSS?
I know that the major difference between id and class is that id can be used once per page but classes can be used as many times on a page as needed. Please clearify this statement and this question. 😊
3 Antworten
+ 4
You mistly have the differences stated in your question. If I want a .red class that simply assigns the color #FF0000 to whatever it's associated with, then that's fine; however, it's not good practice to do that with IDs. Think of a class as more general, while the ID is more specific.
+ 1
Got it.
Thanks @Mario L.
An id is unique. It refers to one element. It may occure only once in the document.
Classes define several related elements. If a class is addressed (e.g. by CSS or JavaScript) all elements belonging to that class are affected.