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

前端 未结 17 2301
长情又很酷
长情又很酷 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:33

    In advanced development ids we can basically use JavaScript.

    For repeatable purposes, classes come handy contrary to ids which supposed to be unique.

    Below is an example illustrating the expressions above:

    this is a box
    this is a box

    Now you can see in here box and box1 are two (2) different

    elements, but we can apply the box and bg-color-red classes to both of them.

    The concept is inheritance in an OOP language.

提交回复
热议问题