Use HTML tag names, classes or IDs in CSS?

前端 未结 12 1726
攒了一身酷
攒了一身酷 2020-12-14 05:13

In designing the HTML and CSS for a page, when should I use

img.className

versus

.clas

12条回答
  •  旧时难觅i
    2020-12-14 05:42

    Yes. You may want to use the same classname for two elements in the future. Be explicit and clear. This will also prevent class-rules from overlapping onto unintended elements.

    h1.title { font-size:18px; } /* My h1's are big */
     p.title { font-size:16px; } /* My p's are smaller */
    
      .title { color:#336699; }  /* All titles are blue */
    

    Use ID's only when necessary, and only once per page.

提交回复
热议问题