What's the difference between an id and a class?

前端 未结 17 2311
长情又很酷
长情又很酷 2020-11-22 01:55

What\'s the difference between

and
when it comes to CSS? Is it alright to use
<
17条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 02:15

    Any element can have a class or an id.

    A class is used to reference a certain type of display, for example you may have a css class for a div that represents the answer to this question. As there will be many answers, multiple divs would need the same styling and you would use a class.

    An id refers to only a single element, for example the related section at the right may have styling specific to it not reused elsewhere, it would use an id.

    Technically you can use classes for all of it, or split them up logically. You can not, however, reuse id's for multiple elements.

提交回复
热议问题