Difference between css class and id

Source: Internet
Author: User

Introduction
If you have not understood its power CSS and web page standard capabilities, the content is marked separately from the design. Therefore, in this tutorial, I will explain how to use the class and id attributes in your XHTML and when to use them.

Class attributes
Only any XHTML element can have a first-class transfer. What is a type of question? So, it is a tricky description. This metaphor has been used, so I will not take credit, but one of its best ways is to think of class and intrusion detection systems. Basically, what you do is create a first-class CSS code and assign it to your XHTML. The following is an example:

<Html>
<Header>
</Header>
<Body>
 
<Div class = "container"> </div>
 
</Body>
</Html>

This ID property
The project ID is almost the same. This is a tricky description of the specific mark. And anything fair will accept class I will accept a number. Therefore, the following is an example of what logo is declared in the zone:

<Html>
<Header>
</Header>
<Body>
 
<Div id = "container"> </div>
 
</Body>
</Html>

How does one notify the only thing that changes the class ID? You may see how they work almost the same.

So what is the difference?

It comes down to one thing: the class can refer to every page more than once, and the ID card can only reference every page again? You may think, "This is very meaningful. The second obvious difference is a fact, that is, a script that can be referenced by the identity used by an element. For example, to obtain a specific number for a JavaScript function, call it. The following is an example:

GetElementByID (intro );

Therefore, if you want to obtain something specific to a string or number, you can use its ID tag content.

Behind Power are class and intrusion detection systems
The power of nature, often beating the fact behind your XHTML code on self-stick notebooks, it can save your time and effort, and we all hope that things can become easier, right? In your external CSS code, if you declare that the area has certain font attributes, click here. For example:

Div # container {
Font-family: Arial, Verdana, sans-serif;
Font-size: 10px;
Line-height: 1.2em;
Color: #999;
}
Now, the content area in all the content will have a font, a size of 12, a row height of 1.2 environmental management system, and a gray color. This is very useful because there is no more font to mark every section, list, title, and table data cell. Next (most important), if you want to change the color of the font throughout the website, you only need to change the line color: #999; to make this effect. Wow, you don't have to modify every font!

This is the tutorial. I hope you understand the power and ease of use of CSS to design your website. If you have any questions, you can visit our forum at any time. Don't be afraid to score (send private messages). For me, if you have any questions through the Forum!
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.