Principles and techniques for using ID and class in XHTML architecture

Source: Internet
Author: User
xhtml| technique The topic of this narrative is how ID and class work, in the title of the use of the principles and techniques, the use of principles and techniques here is my summary of experience, not from which the book, so it is not an authoritative discussion, please netizens in this article when you need to have assertive reading, Don't be fooled by my bogey.

The use principle of ID and class

It is said that the consortium's ID and class setting is unique, and class is universal. So the principle of our use here 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 my own specifications for #logo, #nav, #content, #copyright these are shine. Some people say that layout with ID, color background with class, in fact, this is not true, ID and layout is not directly related to typesetting, class and color is equivalent. Someone to trouble all with ID or all use class, all with class and understandable, all with the ID is not normal, which is contrary to the ID uniqueness. If each ID is different, it must be worn out. The principle I have summed up through practice is that IDs need to be unique and used as much as possible on the periphery. Class is repeatable and is used within the structure as much as possible. 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. You can have two sons, but you can have two dads, that's the truth. When we write CSS, it can be written like this #father. Child {...} Try not to let class contain Id,.father #child {...} It would be a bit ridiculous to write that. Of course, this is not guaranteed, special circumstances need special treatment. But in general this form is not necessarily necessary.

The above is the ID and class use principle, belongs up a word: ID is unique and is the parent, class can be repeated and is a child.

the use of ID and class skills

    1. The name of the child contains the part of the parent name that begins. This facilitates a clear hierarchical relationship when writing CSS.
    2. The child in class is best not with an ID. Of course special circumstances special treatment.
    3. The name of class is best named in case of capitalization. Newmovie this kind of writing and the first combination of the use of a clear relationship is most appropriate. It is important to note that browsers other than IE are sensitive to capitalization. There is the need to start with a letter.

In fact, the above is a number of people understand the content, but I picked up a leak first written down is a summary. I hope you have a new idea for the use of ID and class. Together to sum up the most suitable and most efficient norms to.

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: 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.