[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)