Home  >  Article  >  Web Front-end  >  The difference between Class and ID in div css_Experience exchange

The difference between Class and ID in div css_Experience exchange

WBOY
WBOYOriginal
2016-05-16 12:07:551554browse

A Class is used to define one or more elements based on user-defined criteria. A more appropriate analogy is a script: a Class can define the story line of each character in the script. You can use this class through CSS, Javascript, etc. Therefore, you can use class="Frodo", class="Gandalf", class="Aragorn" on a page to distinguish different story lines. Another very important point is that you can use Class any number of times in a document.

As for ID, it is usually used to define a tag that only appears once on the page. When making a structured layout for page layout (for example, a page usually consists of a header, a , a content area and a footer, etc.), it is generally ideal to use ID, because an ID is in a Can only be used once in the document. These elements rarely appear more than once on the same page.

It can be summed up in one sentence: Class can be used repeatedly but ID can only be used once in a page. It is possible that using the same ID repeatedly will not cause problems in most browsers, but this is definitely an incorrect use according to the standard, and may cause real-life problems in some browsers. (I just tried it in Dreamweaver, and indeed, there was no error)

In actual application, Class may be more useful for text layout, etc., while ID is more useful for macro layout and design placement of various elements. it works.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn