Class命名
- class 名称中只能出现小写字符和连字符(-),例如 .btn 和 .btn-danger。
- class 名称应当尽可能短,并且意义明确。但避免过度任意的简写,.btn 代表 button,但是 .b 不能表达任何意思,只能代表个B
- 使用有意义的名称。使用有组织的或目的明确的名称,不要使用表现形式(presentational)的名称。
- 基于最近的父 class 或基本(base) class 作为新 class 的前缀。
- 使用 .js-* class 来标识行为(与样式相对),并且不要将这些 class 包含到 CSS 文件中。
- 使用 .ui-* class 来做通用UI模块样式声明
选择器
- 对于通用元素使用 class ,这样利于渲染性能的优化。
- 对于经常出现的组件,避免使用属性选择器(例如,[class^=”…”])。浏览器的性能会受到这些因素的影响。
- 选择器要尽可能短,并且尽量限制组成选择器的元素个数,建议不要超过 3 。
- 不采用 class=”btn btn-disabled”,推荐使用 class=”btn disabled” 写法
- 只有在必要的时候才将 class 限制在最近的父元素内(也就是后代选择器)(例如,不使用带前缀的 class 时 — 前缀类似于命名空间)。
扩展阅读:
- Scope CSS classes with prefixes
- Stop the cascade
代码组织
- 以组件为单位组织代码段。
- 制定一致的注释规范。
- 使用一致的空白符将代码分隔成块,这样利于扫描较大的文档。
- 如果使用了多个 CSS 文件,将其按照组件而非页面的形式分拆,因为页面会被重组,而组件只会被移动。
注释规范
/* ==============================
* Copyright: Tencent ISUX - 所属部门
* Project: Qzone Touch - 项目名
* Description: 这里是该文件的介绍,模块/组件说明
* Author: 创建/维护者
* Datetime:2013.10.23 更新日期
============================== */
My brother suggested I might like this website. He was once totally right. This put up truly made my day. You cann’t consider just how much time I had spent for this info! Thank you!
It’s actually a nice and useful piece of information. I’m glad that you shared this useful information with us. Please keep us informed like this. Thanks for sharing.
Hello, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam feedback? If so how do you protect against it, any plugin or anything you can suggest? I get so much lately it’s driving me crazy so any support is very much appreciated.
I appreciate, cause I found exactly what I was looking for. You’ve ended my 4 day long hunt! God Bless you man. Have a nice day. Bye
You made some first rate factors there. I looked on the internet for the issue and located most individuals will go together with with your website.
Its superb as your other articles : D, regards for posting. “Even Albert Einstein reportedly needed help on his 1040 form.” by Ronald Reagan.
I conceive this website holds some rattling superb info for everyone :D. “Believe those who are seeking the truth doubt those who find it.” by Andre Gide.
I love your writing style genuinely loving this web site.
Wow! This blog looks exactly like my old one! It’s on a completely different subject but it has pretty much the same layout and design. Wonderful choice of colors!
you might have an amazing weblog here! would you wish to make some invite posts on my blog?
I’ve been surfing online greater than 3 hours lately, yet I never found any interesting article like yours. It is lovely worth sufficient for me. In my view, if all webmasters and bloggers made good content material as you did, the net can be much more helpful than ever before. “Oh, that way madness lies let me shun that.” by William Shakespeare.
Very interesting details you have mentioned, regards for posting.
Thank you for this beautiful content. I will visit your site more often now and spend a useful time.
Some truly nice and utilitarian info on this internet site, too I think the pattern has got good features.
Your style is so unique compared to many other people. Thank you for publishing when you have the opportunity,Guess I will just make this bookmarked.2
Wonderful blog! I found it while browsing on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Many thanks
I conceive this site has some real great information for everyone : D.