Cascading style sheets use “id” or “class”

后端 未结 15 2417
夕颜
夕颜 2020-12-05 16:11

when styling specific html elements, i tend to always use the class attribute. the css code looks cleaner imo.

why do both exist which one should you use and when ?<

15条回答
  •  [愿得一人]
    2020-12-05 16:41

    I mostly use ID to identify specific elements within elements already having a class assigned. That way I can identify easier what element gets which styling.

    Not really sure if there is a real other difference between them, other than that you can only use an ID once in a page...

提交回复
热议问题