Principles and skills for applying IDs and classes in the XHTML structure

Source: Internet
Author: User
The topic of this article is how to use ID and CLASS. I have mentioned application principles and skills in the title. The Application principles and skills here are my experience summaries, not from which books, therefore, it is not an authoritative discussion. please refer to the topic of this article, that is, how to use ID and CLASS, and the principles and skills of application are mentioned in the title, the application principles and skills here are my summary of experience, not from which book, so they are not authoritative discussions. please have an idea to browse this article, do not be confused by my enchanting words.

Application principles of ID and CLASS

It is said that W3C sets IDs and classes to be unique and has a wide range of classes. Therefore, our application principles here are also based on this feature. IDS cannot be repeated. Therefore, in the XHTML structure, the large structure must use IDs. Such as tag, navigation, subject content, and copyright. The naming rules I have developed are # logo, # nav, # content, # copyright. Some people say that layout uses ID and color background uses CLASS, which is really inaccurate. ID has no direct relationship with layout, and CLASS and color are equal. Some people use IDs or all use classes for the sake of trouble. it is also understandable that it is not normal to use all IDs, which is contrary to the uniqueness of IDs. If each ID is different, it is not exhausting. The application principle I have summarized through practice is: ID must be unique and should be used as far as possible. The CLASS is reproducible and should be used within the structure as much as possible. This is beneficial to the protection and correction of website code in the future. This will make all the classes become sub-or grandchildren of IDs. You can have two sons, but can you have two fathers. When we write CSS, we can write it like this # father. child {...} Try not to include the Class ID,. father # child {...} It seems a bit ridiculous to write it like this. Of course, this is not a matter of course. it should be taken into special consideration in special cases. However, this situation is usually not necessary.

The above is the application principle of ID and CLASS. In a word, ID is unique and has a parent level, and CLASS can be repeated and sub-level.

Application skills of ID and CLASS

  1. The child-level naming contains the part of the parent name that starts. This helps you understand the hierarchy when writing CSS.
  2. It is best not to use ID for the child level in the CLASS. Of course, special situations are special.
  3. CLASS naming is best case-sensitive and practical. For example, newMovie is the most suitable method to work with the first article to understand the relationship. Note that browsers other than IE are very case sensitive. Also, it must start with a letter.

In fact, all of the content above is what everyone understands, but it is a summary to write it down first. I hope that you will come up with new ideas for the application of ID and CLASS. Summarize the most appropriate and efficient specifications.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.