Difference between class and ID in Div + CSS

Source: Internet
Author: User

A class is used to define one or more elements according to user-defined standards. For example, a script: A class can define the story line of each character in the script. You can use this class through CSS and JavaScript. Therefore, you can use class = "Frodo", class = "gandalf", class = "Aragorn" on a page to differentiate different story lines. Another important thing is that you can use any number of classes in a document.

ID is usually used to define a tag that appears only once on the page. In structured layout of page layout (for example, a page is usually composed of a header, a header <masthead>, a content area, and a footer), generally the ID is ideal, because an ID can only be used once in a document. These elements are rarely larger than once on the same page.

In one sentence, the class can be used repeatedly, and the ID can only be used once on a page. It is possible that the same ID will not be used repeatedly in many browsers, but it is definitely incorrect in terms of standards, and it may lead to practical problems in some browsers. (I tried it in Dreamweaver just now. Indeed, there is no error)

In practical application, the class may be useful for text layout, and the ID is useful for macro layout and design of various elements.
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.