CSS 的 ID 和 Class 有什么区别?如何正确使用它们?

关注者
180
被浏览
35433

22 个回答

ID's are unique.
Each element can only have only one ID.
Each page can have only one element with that ID

Classes are NOT unique
You can use the same class on multiple elements.
You can use multiple classes on the same element.

CSS doesn't care,But Javascript cares.
为什么?