Difference between ID and class

Source: Internet
Author: User

First, we will introduce the differences between id and class:
1. id is a label used to distinguish between different structures and content. id is to first locate the structure/content and then define the style. class is a style, it can be applied to any structure or content. class defines a style and then applies it to multiple structures or contents.
2. id is the element name, which can be accessed by js or other script programs, and class is the css class Name of the element.
3. When defining a style, use # aa {...} for id = "aa" and use. bb {...} For class = "bb {...}.
4. class is a global attribute, and id is a local attribute.
The following code is displayed:
<Div id = "aa" class = "bb"> test </div>
# Aa {width: 300px; height: 50px; background-color: Red ;}
. Bb {width: 100px; height: 300px; background-color: blue ;}
How can this problem be displayed?
The answer is: display as a test text block with a width of 300, a height of 50, and a red background. Because the class is a global attribute and the id is a local attribute, the display style is that after the class defines this attribute, the newly defined attribute of id is added. When the class and id attributes are repeated, take the attributes of id. It is similar to the parent-child inheritance relationship in programming.

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.