[CSS Basics] Difference between Class and ID in CSS

xiaoxiao2021-04-05  300

(http://www.8go8.com/blog/post/20060612013036.html)

These two differences are more confusing problems, especially Class and ID, I believe that many people have not taken a careful understanding. The following is some of my understanding: 1. The difference between Class and ID A class is used to define one or more elements according to user-defined criteria. Take a more appropriate than the Scripture: A class can define the storyline of each person in the script, you can use this class through CSS, JavaScript, etc. So you can use class = "frodo", class = "gandalf", class = "avigorn" to distinguish between different stories on one page. It is also very important that you can use any number of Class in a document. As for the ID, it is usually used to define a mark on the page. When structured in the page version (for example, a page is composed of one header, a header, a content area, and a footer, etc.), generally use ID, because one ID is only in one document Can be used once. These elements rarely appear more than once in the same page. In summary: Class can be repeatedly used and the id can only be used once in one page. It is possible to repeatedly use the same ID in a large part of the browser without problems, but this is definitely wrong to use, and it is likely to lead to some browser real issues. (I have just tried it in Dreamweaver, and there is no error.) When practical, Class may be more useful for text version of the text, and ID is more useful for macro layout and design. 2. MARGIN and PADDING are the most important roles in the form. The table is most clear in the form. Especially after the background pattern is loaded on a zone, the background color under padding changes, while Margin will not change.

转载请注明原文地址:https://www.9cbs.com/read-132238.html

New Post(0)