CSS selector: class and ID &

Source: Internet
Author: User
CSS selector: both class and id can make the "single selector" have different styles.
A1: What are the main differences between the two?
Id. You can only define a single element. The page does not have any problems, but W3 detects that your page does not conform to the standard. class is a class, and the same class can define multiple elements. In terms of page effects, the visual effects of the two things are almost identical.
A2: Why is the id selector less usable? What are its limitations?
The id is used for a single style. The id is used for the style dynamically controlled by the program and js. The id can only be used once on the page! Provide less id, because the id may conflict with the page embedded program (such as the same name )!
A3: When should I use ID and class?
A single element, or something that requires Program and JS control, needs to be defined by id; elements and categories that are reused, are defined by class.
Related articles: Test the priority of applying multiple classes to the same element!
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.