When CSS beginners first start using div+css layout, they are often troubled by a question: when defining an attribute, should you use id or class? Here I will talk about my principles for using ID and class in my work. Hope it helps beginners.
[b]Principles of using ID[/b]
We know that IDs are unique, which means that IDs cannot be repeated in the entire xhtml, so when we write web pages, IDs are used for large structures, such as logo, navigation, main content, copyright, etc., according to naming standards. Name it #logo, #nav, #contenter, #copyright. Another situation is: when we want to apply a layer through js to achieve a certain effect, we use id. This is also determined by the uniqueness of the id.
[b]Principles of using class[/b]
Class is universal in CSS definition and can be reused infinitely, which also reflects the superiority of div+css layout. Class is often used inside the structure. The advantage of this is that it is beneficial to the later maintenance and modification of the website code. This will make all classes the children or grandchildren of id.
Another thing to note is that try not to let the class contain id, such as .ff #childer{. ..}, this is obviously undesirable and inconsistent with writing habits. I have also introduced good writing habits before, which are very beneficial to writing standardized code, cooperating with other colleagues, and even later maintenance.