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 line for each character in the script, and you can use it through css,javascript. So you can use class= "Frodo" on one page, class= "Gandalf", class= "Aragorn" to distinguish different story lines. It's also very important that you can use any number of classes in a document.
  
As for the ID, it is typically used to define the markup that appears only once on the page. When a page layout is structured (for example, a page is usually composed of a header, a header , a content area, and a footer), it is generally ideal to use an ID, because an ID can only be used once in a document. These elements rarely appear larger than once on the same page.
  
summed up in a sentence is: class can be used repeatedly and ID in a page can only be used once. It is possible to reuse the same ID in a very large number of browsers without problems, but on the standard it is absolutely wrong to use, and it is likely to lead to real-world problems with some browsers. (I just tried it in Dreamweaver, and there's no mistake, really)
  
In practical applications, class may be more useful for text typesetting, and the 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.