What is the best approach to implementing CSS styles?

I'm trying to decide the best approach to implementing the majority of CSS styles on my page. The 2 approaches I have recognized are: 1) To attach a class attribute to most elements and style each class like so:
fieldset.MyForm { }
legend.MyForm { }
2) To attach class attributes to container elements and style nested elements like so:
.MyForm fieldset { }
.MyForm legend { }
From my experimentation with both approaches: 1) seems more accurate, with less chance of unwanted inheritances or having to overrule existing classes to get a style working but since styles aren't shared I need to continually redefine them. 2) is more elegant from a backend perspective, as I don't need to define class attributes everywhere, but sometimes requires me to define .Classes .Of .Increasing .Depth to overrule existing styles due to CSS specificity. What is the better approach in terms of code readability/scalability/maintainability? Is there another, better approach I haven't identified? Thanks

以上就是What is the best approach to implementing CSS styles?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准