The difference between class and ID in Div+css _ Experience Exchange

Source: Internet
Author: User
A class is used to define one or more elements based on user-defined criteria. A more appropriate analogy is the script: A class can define the story lines of each character in the script, and you can use this class by Css,javascript. So you can use class= "Frodo" on one page, class= "Gandalf", class= "Aragorn" to distinguish different story lines. It is also very important that you can use any number of classes in a document.

As with IDs, it is often used to define a single mark on the page that appears only once. When you make a structured layout of page layouts (for example, usually a page is made up of a header, a header <masthead>, a content area and a footer), it is generally ideal to use IDs because an ID can only be used once in a document. These elements rarely appear more than once on the same page.

The sentence is: class can be used repeatedly and IDs can only be used once in a page. It is possible that using the same ID repeatedly in a large number of browsers will not cause problems, but it is definitely wrong to use on the standard and is likely to lead to some real-world problems with browsers. (Just tried it in Dreamweaver, yes, no mistake)

In practical applications, class may be useful for text typesetting, and ID is useful for macro layout and design placement 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.