Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between class and id in html5

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what are the differences between class and id in html5, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

Differences: (1) the scope of action of class is larger than that of id; (2) the priority of id selector is higher than that of class selector with different priority level; (3) the syntax of css is different, and class passes "." Select, id through "#" selection.

The operating environment of this tutorial: windows10 system, HTML5 version, Dell G3 computer.

What are the differences between class and id in html5

Id

Is a unique identifier, which is similar to our ID card number to quickly obtain the label object and operate on it.

When we use id to modify the label style, we use # id to represent it

Class

Point to one category, that is to say, if there are four tags with the same style, for convenience, we put the styles of these four tags into a Class. When needed, we directly let the tags inherit from this Class class to reduce the amount of code. If you still need precise control in the four tags, we can use id with class to control a tag at the same time!

When we use Class to modify the label style, we use .Class to represent it.

The differences are as follows:

The scope of function is different: the scope of class is larger than that of id, and id means that it is uniquely identified, just like our personal ID card, which can only be called once in a page. Generally speaking, a web page does not set up two or more id. The scope of class is more extensive. Class is a class tag that can be called multiple times in an interface. Can be reused.

Priority varies: the priority of the id selector is higher than that of the class selector. Id selectors can be used for the more important ones.

The syntax used is different: the way id selectors are used in css, such as using div as an example: (for example, there are div id='i' … And div class='c'... Two div boxes, referenced in css as follows:)

C {attribute: attribute value;} # I {attribute value;} Thank you for reading this article carefully. I hope the article "what is the difference between class and id in html5" shared by the editor will be helpful to you. At the same time, I hope you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report