The use principle and skill of ID and class in DIV CSS page layout

Source: Internet
Author: User
css| Skills | Web page

ID and class How to use, 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 is not what authoritative discussion, please users in this article when you need to have assertive reading, do not be confused 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 not 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 child's named contains the part of the parent name to begin with. This facilitates a clear hierarchical relationship when writing CSS.

2, the child in class is best not without ID. Of course special circumstances special treatment.

3, class naming the best name with the case of combination. 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.



Related Article

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.