why use id's & class's in html why not just one?

后端 未结 4 379
春和景丽
春和景丽 2020-12-22 11:17

i understand what there is a difference between id\'s and class\'s - ids and ment to be given to a unique item, and class\'s and like tags, they can be given to multiple ite

相关标签:
4条回答
  • 2020-12-22 11:47

    concise answer:

    id - Shows on your page once.

    class -Shows on your page more than once.

    0 讨论(0)
  • 2020-12-22 12:00

    Imagine if you had a load of buttons that looked the same on the page. Would you want to repeat yourself numerous times in your CSS? Or use a class and write it once.

    This is applicable in any case of the same styling on different elements.

    0 讨论(0)
  • 2020-12-22 12:12

    Adding to Sam's answer. Ids are helpful both for styling and javascript. If you want only a particular style applied or want to increase the specificity of your css id come handy.

    0 讨论(0)
  • 2020-12-22 12:14

    #id is used to describe the document structure or important containers/elements and they must be unique entries.

    .class is used to describe elements which are can be many elements in this documents.

    If you try to validate the document and have many id's this will be error and if you want your document to be valid you must rename the id's of use classes.

    Classes are useful because they can be many classes with one name on your document and you will not be force to copy/paste style from one element to another and change only the tag to describe the new element.

    0 讨论(0)
提交回复
热议问题