Http://www.8go8.com/blog/post/20060612013036.html
)
These two differences are confusing, especially the class and ID. I believe many people have not carefully understood the differences. Some of my understandings are as follows:
1. Differences between class and ID
A class is used to define one or more elements according to user-defined standards. For example, a script: A class can define the story line of each character in the script. You can use this class through CSS and JavaScript. Therefore, you can use class = "Frodo", class = "gandalf", class = "Aragorn" on a page to differentiate different story lines. Another important thing is that you can use any number of classes in a document.
ID is usually used to define a tag that appears only once on the page. In structured layout of page layout (for example, a page is usually composed of a header, a header, a content area, and a footer), the ID is generally ideal, because an ID can only be used once in a document. These elements are rarely larger than once on the same page.
In one sentence, the class can be used repeatedly, and the ID can only be used once on a page. It is possible that the same ID will not be used repeatedly in many browsers, but it is definitely incorrect in terms of standards, and it may lead to practical problems in some browsers. (I tried it in Dreamweaver just now. Indeed, there is no error)
In practical application, the class may be useful for text layout, and the ID is useful for macro layout and design of various elements.
2. Differences between margin and padding
Both of them replace the most important function of the table-> A good way to split blocks, the difference is that margin is the distance between different tags, and padding is used to separate different content in the same element, this is the most visible in the table. Especially when the background style is loaded for a region, the background color of the content under the padding changes, while the margin does not.