What is the difference between id and class in html

青灯夜游
Release: 2021-11-18 11:19:31
Original
16826 people have browsed it

Difference: 1. The scope of class is larger than that of id. ID is unique and can only be called once in a page, while class can be called multiple times; 2. ID corresponds to the style selector of CSS. is "#", and the style selector corresponding to class in CSS is "."; 3. The priority of the id selector is higher than the class selector.

What is the difference between id and class in html

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

Comparison of class and id in Html:

1. The scope of effect is different:

class has a larger range than id, which represents a unique identifier, just like our personal ID card. It is unique and can only be called once on a page. Generally, a web page does not have two or more IDs. The scope of class is wider. Class is a class label and can be called multiple times in an interface. Can be reused.

2. The syntax used is different:

How the id selector is used in css, such as using div as an example: (For example, there are div respectively id='i'... and div class='c'...Two div boxes, the methods quoted in css are as follows:)

.c{
属性:属性值;
} 
#i{
属性:属性值;
}
Copy after login

3. Priority The levels are different:

The priority of the id selector is higher than the priority of the class selector. For more important ones, you can use the id selector.

Recommended tutorial: "html video tutorial"

The above is the detailed content of What is the difference between id and class in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!