Difference between CSS Classes and ID

Source: Internet
Author: User

When people often confuse CSS IDs and CSS classes, they should be used. This lesson is to show differences and provide more information about CSS IDs.


What is number selection?
W3C defines the class ID as "a unique identification sign, with a component ". But what is the actual meaning? I hope you have read the lessons of our CSS class. If not, we recommend that you do this.

The ID card CSS is similar to the class they are identified for special circumstances, an integral part. The following is an example of a CSS number.

P # exampleID1 {background-color: white ;}
P # exampleID2 {text-transform: uppercase ;}

Html code.

<P id = "ExampleID1"> This paragraph has an ID name
"ExampleID1" and has a white CSS defined background </p>

<P id = "ExampleID2"> This paragraph has an ID name
"ExampleID2" and has had its text transformed to uppercase letters. </p>

Note that the CSS of a serial number is an HTML element followed by a "#" and the name of the final serial number. The final result looks like "element # idname ". In addition, we must learn this in real time. Numbers are used in HTML. We must use "number = name" instead of "class = name" for reference!

Why do they choose these names? ?
ID = the ID of a person is the only one.
Class = There are many people in the same class.
Number: layout and uniqueness
The standard stipulates that the name of any specific number can only be referenced once on a webpage or file. Based on our experience, ID is the most commonly used correct CSS layout. This makes sense, because there is usually only one menu per page, one flag, and usually only one content pane.

In the CSS layout instance of Tizag.com, we use the unique identification of the above items. View the CSS code as an example of our first layout. The following is a unique identifier in our code.

Menu-area # m enuPane
Content-area # content
Answer: category and ID card
When using an ID card, only one occurs on each webpage. When used, one or more of the class occurs on each webpage.

 

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.