CSS Beginners: ID and class selection

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

CSS beginners are often bothered by a problem when they start using the div layout: When defining a property, is it using an ID, or is it using class? Here I talk about the principles of using ID and class in my work. Hope to help beginners.

Principle of use of IDs

We know that ID is unique, that is, the ID in the entire XHTML can not be duplicated, so we write the page, the large structure with ID, such as: logo, navigation, subject content, copyright, according to the naming code, respectively named #logo, #nav, #contenter, # Copyright。 There is another situation: we have to use JS to effect a layer to achieve a certain effect, with the ID. This is also determined by the uniqueness of the ID.

The use principle of class

Class is universal in CSS definition and can be reused infinitely, which also embodies the superiority of div layout. Class is commonly used within structs, and the benefit of this is that it facilitates late maintenance and modification of site code, which makes all classes a child or grandchild of the ID.

Also note that try not to let class include IDs, such as. ff #childer {...}, which is obviously undesirable and does not conform to the writing habit. Also introduced in front of good writing habits, the code to write norms, and other colleagues to cooperate, so that later maintenance is very good.

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.