Class or ID on Body Tag

前端 未结 6 656
抹茶落季
抹茶落季 2021-01-01 11:40

I\'ve been applying an ID to the body tag of my HTML documents lately to allow greater CSS control (#9). Recently the though occurred to me that I could do exactly the same

6条回答
  •  感情败类
    2021-01-01 12:03

    ID needs to be unique per page (if you want valid markup), meaning only one instance of a particular ID should exist on a page.

    Classes, on the other hand, can be applied to numerous elements per page. Use classes for things that reuse the same styles and use IDs for more unique elements that require their own styling.

    Ideally, use classes whenever possible and limit the use of IDs.

    For more information on ID, see here, and more on classes, see here.

提交回复
热议问题