Best practice for CSS class naming for use with jQuery selectors

前端 未结 6 2039
北恋
北恋 2020-12-28 15:55

While building a Javascript-heavy web application, what is the best practice for naming CSS classes to keep the Javascript code and CSS stylesheets clean and the UI structur

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-28 16:44

    Option 1: Name every single element uniquely.

    This is next to impossible and definitely not a best practice. I think it's better if you can use classes that makes sense by grouping relevant styles and properties.

    Option 2: Name every element semantically, and select elements hierarchically.

    I prefer this one. At least you know the flow and where things are.

    Option 3...n: Some hybrid approach? A totally different approach altogether?

    There's always a hybrid approach and totally different approach. I think every developer has their own style of coding. If it's sematically correct and well structured, that would be the best approach.

提交回复
热议问题