Belongs up one word: ID is unique and is parent, class is repeatable and child-level. Keeping a good code writing habit can be a great help for future code maintenance.
Many divcss layout techniques have been discussed in the previous articles in webjx.com. When using CSS to control the layout of a Web page, we may all have a problem: when defining an attribute, is it using ID or class? Today webjx.com again talk about the use of ID and class principles, the usual time to do the station's experience to you briefly, I hope to be able to help you.
Principle of use of IDs
First of all, Id,id is unique, and its use principle is based on this feature. IDS cannot be duplicated, so in the structure of XHTML, the large structure must be with an ID. such as logo, navigation, subject content, copyright. These are named after the #logo, #nav, #content, #copyright, etc., in accordance with the principles of its uniqueness. The garden suggests defining IDs as far as possible on the periphery.
The use principle of class
Class is universal in the definition of CSS. The white point is that class has a repeatable unlimited number of uses many times, the garden suggests that you try to use within the structure. The benefit of this is that it helps to maintain and modify the site code later, so that all classes become children of IDs or grandchildren. When we write CSS, it can be written like this #father. Child {...}, the other thing to note is try not to let class contain IDs, such as. Father #child {...} If it's written in this way it's obviously very undesirable. Of course, this is only relative to the good writing habits of some suggestions, only for your reference.
To sum up, belongs up a word: ID is unique and is a parent, class can be repeated and is child-level. Keep a good code writing habits for future code maintenance will be a great help, if you have better suggestions, please leave a message for me to explore.