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 id and class in css

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the difference between id and class in css", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "what is the difference between id and class in CSS"!

difference

ID should be preceded by the prefix symbol "#", while class should be preceded by the prefix symbol ". "。

The id attribute can generally be used only once in a page, while class can be referenced multiple times.

id as an element label, used to distinguish between different structure and content, and class as a style, it can be applied to any structure and content.

In the layout idea, generally adhere to the principle: id is to determine the structure and content of the page first, and then define the style for it: and class on the contrary, it first defines a class style, and then the page according to the need to apply the class style to different elements and content above.

Browsers currently allow multiple ids with the same attribute value to appear on the same page, and in general it can be displayed normally, but errors occur when using javascript to control elements by id.

In practice, class is more often applied to text blocks and page decoration, while id is more often used to implement grand layouts and design styles that contain blocks or boxes.

Css three ways to introduce 1. inline style, the most direct and simple one, directly to the HTML tag using style="". 2. Inline style, that is, CSS code written in between, and with

Make a statement. 3. External style, where the link style is the most frequently used and most practical style, only need to add between

That's it. The second is to import style, import style and link style are similar, use @import style to import CSS style sheet, not recommended. At this point, I believe that everyone has a deeper understanding of "what is the difference between id and class in css", so you may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue 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

Internet Technology

Wechat

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

12
Report