CSS Optimization: Element ID vs. Class

前端 未结 2 1039
我寻月下人不归
我寻月下人不归 2020-12-09 04:39

With MVC and jQuery I am making significantly more use of CSS. A question that came to mind is what is the best approach for using Element IDs vs. Classes. If I use Element

2条回答
  •  情书的邮戳
    2020-12-09 05:40

    I generally prefer the class method. The reason being that you don't have to write up a new css selector for each new ID'd element in your system.

    Also, I tend to differentiate between "structure" and "style" css. Meaning, that I separate things that deal with size (width / height) and position from css classes that do font-weight, color, etc.

    For non-changing structural framework pieces, I'll use ID's. For parts that may have multiple representations in the HTML, I'll stick with class mechanisms.

提交回复
热议问题