最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Are there CSS class naming standards for web applications? - Stack Overflow

programmeradmin8浏览0评论

There is quite a bit of information on the intertubes going over some fundamental css naming conventions. However, most of these conventions are from designer's point of view.

I'm going after conventions from a web application developer's point of view. As a web application grows, and UJS (unobtrusive javascript) is used throughout the codebase, what naming standards have grown around your css classes. The reason this is a little awkward is that css classes are somewhat overloaded in their use.

  • On one hand, css classes are used by stylesheets to help present your content well.
  • On the other hand, css classes are used by UJS libraries (like jQuery) to help tie javascript code to certain elements on a given page.

A covention that es to mind from a rails application perspective is something like

.controller-action 
  { /*styles */ }

Other thoughts are prefixing your classes with hungarian-notion:

.js-controller-action
  { /* styles */ }

the js, prefix, would delineate those elements with ujs code attached to them.

Personally, I'm interested in this from a rails application perspective, however, I can see how this could apply to any web application framework and UJS javascript library.

There is quite a bit of information on the intertubes going over some fundamental css naming conventions. However, most of these conventions are from designer's point of view.

I'm going after conventions from a web application developer's point of view. As a web application grows, and UJS (unobtrusive javascript) is used throughout the codebase, what naming standards have grown around your css classes. The reason this is a little awkward is that css classes are somewhat overloaded in their use.

  • On one hand, css classes are used by stylesheets to help present your content well.
  • On the other hand, css classes are used by UJS libraries (like jQuery) to help tie javascript code to certain elements on a given page.

A covention that es to mind from a rails application perspective is something like

.controller-action 
  { /*styles */ }

Other thoughts are prefixing your classes with hungarian-notion:

.js-controller-action
  { /* styles */ }

the js, prefix, would delineate those elements with ujs code attached to them.

Personally, I'm interested in this from a rails application perspective, however, I can see how this could apply to any web application framework and UJS javascript library.

Share Improve this question asked Sep 9, 2009 at 4:50 munity wiki
casademora 2
  • The motivation for this question is the software development principle that your code should be as self documenting as possible. Does this apply to css classes in your markup in relation to UJS code? – casademora Commented Sep 9, 2009 at 4:57
  • I would consider the "UJS" Hungarian notation itself obtrusive. – Christopher Parker Commented Apr 22, 2010 at 16:11
Add a ment  | 

1 Answer 1

Reset to default 6

I found a good article on this.

Structural Naming Convention in CSS

and also

CSS coding: semantic approach in naming convention

发布评论

评论列表(0)

  1. 暂无评论