The use principle of ID and class in div

Source: Internet
Author: User
Keywords Web page production CSS Tutorials
Tags class code control use web web page

This article describes the div CSS in the ID and class use principle, in the previous article discussed a lot of div css layout skills, we use CSS to control the layout of the page we may encounter a problem: when defining a property, is the use of ID, or use class? Here and you explain, I believe this introduction will let you have some harvest.

ID and Class usage rules in DIV CSS

In the previous article in 51cto.com discussed a lot of div css layout techniques. 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 51cto.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 ID. such as logo, navigation, subject content, copyright. These are named after the #logo, #nav, #content, #copyright等等, in accordance with the principles of its uniqueness. The garden suggests defining IDs to be used 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 can be written like this #father.child{&hellip, the other thing to note is to 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.

Summary

To sum up, aggregation up a word: ID is unique and is a parent, class can be repeated and is a child. 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.

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.