Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the differences between id and class in css

Shulou Source: shulou.com Published: 2022-05-31 13:22:20 10月03日 Update

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!

Tags: Style content page application element more structure different practical between prefix actual that is attributes layout tags symbols links learning deeper Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information OPPO Reno Xiaomi Linux