CSS ID vs Class

前端 未结 5 1087
走了就别回头了
走了就别回头了 2020-12-03 15:11

What is the basic difference between CSS ID and CSS Class?

Someone told me that, ID can be used only once in a page. But I found that it can be used multiple times.<

5条回答
  •  猫巷女王i
    2020-12-03 16:05

    Think of ID like your Student ID. Only one exists in your school - yours. Think of class like a group of kids...all of whom belong to the same class: "Biology". If you want to address a specific student, you would do so by acknowledging his/her ID - since that will never address more than one student. If you wanted to address a group of students, you could do so by acknowledging their class - "The biology class will be enjoying pizza today" vs "Jonathan Sampson will be enjoying pizza today".

    
      
      
      
    
    

    Takeaway:

    • ID = Student ID (Schools don't issue identical IDs to multiple students)
    • CLASS = Group of Students (Like 'The Biology Class' will be going on a fieldtrip)

提交回复
热议问题