css div id used only once per page

后端 未结 7 552
醉梦人生
醉梦人生 2021-01-14 03:27

In using CSS is it best practice to use a div id only once per page. I know each id has to be unique but could be used multiple times. A discussion with my development tea

7条回答
  •  鱼传尺愫
    2021-01-14 03:51

    You can certainly use the id="" attribute as many times as you need, but the contents of the attribute should be unique. Not having a unique value is a HTML error.

    If you need multiple items to have the same attribute, then you can set them as a class.

    More info is at the W3C - Element identifiers: the id and class attributes (the HTML 4.01 Specification).

提交回复
热议问题