In-depth analysis of the difference between ID and CLASS in CSS styles

Source: Internet
Author: User

[Document of the fire School of website construction] Today, a friend asked CSS questions in the group. When talking about the difference between Class and ID, I suggested Baidu. Then he checked a lot of articles, I still don't quite understand it, so I had to give it a one-by-one analysis.

Class is the class for setting labels.

Id is the identifier of the tag.

The class attribute is used to specify the style of an element.

For example, you can add a style sheet.

. Title {

Font-size: 14px;

Font-weight: bold;

}

Usage: class = "title"

The id attribute is used to define a unique style of an element.
 
For example, a CSS rule:

# Container

{
Width: 1004px;
Margin: 0 auto;
Text-align: left;
}

Method of use: id = "container", id is a tag used to distinguish different structures and content, just like your name. If two people in a room have the same name, obfuscation occurs;

A class is a style that can be embedded in any structure or content, just like a dress;

The concept is different:
Id is to first find the structure/content, and then define the style; class is to first define a style, and then set to multiple structures/content.

Okay, so far, what we have mentioned above is very clear. No matter id or class, it can easily achieve special effects, which is simple and convenient. I hope all the friends in the group can understand it, I also hope to give others a learning opportunity. (Text/floating)

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.