Use HTML tag names, classes or IDs in CSS?

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

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

img.className

versus

.clas

12条回答
  •  天命终不由人
    2020-12-14 05:39

    I know this is a pretty old question but for all those who are reading this just now... There are 4 categories of rules in general: ID Rules, Class Rules, Tag Rules, Universal Rules. And it's important to mention that class selectors are faster than tag selectors. So you should always use them in the following order
    1. ID Selector
    2. Class Selector
    3. Tag Selector
    4. Universal Selectors

    In your case you should never use the tag name before class name.

    You can find more information here: Writing efficient CSS

提交回复
热议问题