Skip to content

Commit 1e37256

Browse files
committed
update chinese
1 parent 9822e3b commit 1e37256

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

cn/README.md renamed to zh-cn/README.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@
3535
----------
3636

3737

38+
# 代码书写指南
39+
40+
参考摘自 [file an issue on GitHub](https://github.com/mdo/code-guide),有改动。
3841

3942
## 黄金法则
4043

4144
> 任何代码库中的所有代码应该看起来像是一个人书写的,不管有多少人贡献过代码。
4245
43-
这意味着任何时候都要严格执行这些商定的准则。对于增加或减少代码的法则,请参看 [file an issue on GitHub](https://github.com/mdo/code-guide).
44-
45-
46+
这意味着任何时候都要严格执行这些商定的准则。对于增加或减少代码的法则,请参看 [Code-guide](https://github.com/webcoding/code-guide/tree/master/zh-cn).
4647

4748
----------
4849

49-
50-
5150
## HTML
5251

5352

@@ -129,21 +128,41 @@ HTML 属性应该遵循特定的顺序,以便能更易阅读代码。
129128

130129
## CSS
131130

132-
### CSS 语法
131+
### 外部CSS引用
133132

134-
* 使用两个空格的 soft-tabs
133+
必须使用如下格式(rel在前,href在后,无type="text/css"及charset):
134+
135+
````<link rel="stylesheet" href="css_example_url">
136+
````
137+
138+
### CSS 注意事项
139+
140+
* 无特殊说明,编码统一为utf-8;
141+
* 防止文件合并及编码转换时造成问题,请将样式中文字体名字改成对应的英文名字(unicode码),如:宋体( \5b8b\4f53)微软雅黑(”Microsoft YaHei”,”\5FAE\8F6F\96C5\9ED1″);
142+
* 书写代码前,考虑并提高样式重复使用率;
143+
* 禁止使用 `expression` 表达式;
144+
* 禁止滥用 `!important`
145+
* 能缩写的尽量缩写,如 `padding:5px 0 0 5px;`
146+
* 层级(z-index)必须清晰明确,适当划分组件层级范围,禁止层级间盲目攀比;
147+
* 为方便组件模块化和提高弹性,正常情况下,为避免外边界冲突,组件不应设置外边界,外边界用组合css方式实现,如:m10{margin:10px}mt10{margin-top:10px}等;
148+
* 必须为大区块&重要模块的样式添加注释,小区块适量注释;
149+
* 正式发布前应进行压缩,压缩后文件的命名应添加”.min”后缀;
150+
* 代码缩进与格式:请参照以下 CSS 书写规范;
151+
152+
### CSS 书写规范
153+
154+
* 使用四个空格的 soft-tabs 缩进
135155
* 写组选择器时,保持选择器各占一行
136-
* 在声明块的左 “{” 前应该有一个空格
137-
* 关闭块的 “}” 要新行显示
138-
* 在每个属性的 <code>:</code> 后包含一个空格
139-
* 每个声明应该自己独占其行
140-
* 每个属性以 “;” 结尾
141-
* 分割选择器的 “,” 后应该包含一个空格
156+
* 在属性块的左 “{” 前应该有一个空格
157+
* 关闭属性块的右 “}” 要新起一行
158+
* 每个属性的 “:” 后包含一个空格
159+
* 每个属性应该自己独占一行
160+
* 分割选择器的 “,” 后应该包含一个空格
142161
* Don't include spaces after commas in RGB or RGBa colors, and don't preface values with a leading zero
143-
* 小写所有16进制值, 例如, <code>#fff</code> 而非 <code>#FFF</code>
144-
* 使用简写16进制值, 例如, <code>#fff</code> 而非 <code>#ffffff</code>
145-
* 选择器中引用属性值, 例如, <code>input[type="text"]</code>
146-
* 避免0值设置单位, 例如, <code>margin: 0;</code> 而非 <code>margin: 0px;</code>
162+
* 小写所有16进制值, 例如, `#fff` 而非 `#FFF`
163+
* 使用简写16进制值, 例如, `#fff` 而非 `#ffffff`
164+
* 选择器中引用属性值, 例如, `input[type="text"]`
165+
* 避免0值设置单位, 例如, `margin: 0;` 而非 `margin: 0px;`
147166

148167
**错误示例:**
149168

@@ -169,7 +188,7 @@ HTML 属性应该遵循特定的顺序,以便能更易阅读代码。
169188
}
170189
````
171190

172-
这里使用的术语有问题?参见 [syntax section of the Cascading Style Sheets article](http://en.wikipedia.org/wiki/Cascading_Style_Sheets#Syntax) on Wikipedia.
191+
常见的CSS术语,请参见 [syntax section of the Cascading Style Sheets article](http://en.wikipedia.org/wiki/Cascading_Style_Sheets#Syntax) on Wikipedia.
173192

174193

175194
### 属性顺序
@@ -220,12 +239,14 @@ HTML 属性应该遵循特定的顺序,以便能更易阅读代码。
220239
当使用供应商前缀的属性时,每个属性缩进到vlaue值垂直对齐的位置,方便多行编辑。
221240

222241
````css
242+
/* Corner radius-圆角 */
223243
.selector {
224244
-webkit-border-radius: 3px;
225245
-moz-border-radius: 3px;
226246
border-radius: 3px;
227247
}
228248
````
249+
注:`-khtml-border-radius: 3px;` 是苹果的那个浏览器的,现在使用 `-webkit-`
229250

230251
在 Textmate、Sublime Text 2 以及 notepad++等工具中, 都支持多行编辑。
231252

@@ -278,13 +299,14 @@ In Textmate, use **Text &rarr; Edit Each Line in Selection** (&#8963;&#8984;A).
278299
}
279300
````
280301

281-
#### 类名
302+
#### 类名与命名
282303

283304
* 保持类名使用小写字母或连接符 (不要使用下划线或驼峰命名法)
284305
* 避免使用随意的首字符命名法
285306
* 保持命名尽可能短并简洁
286307
* 使用有意义的命名;使用结构化或目的性的意义名称
287308
* 根据最近的父组件基类作为命名前缀
309+
* 为JavaScript预留钩子的命名,请以 JS_ 起始,比如:JS_ui-tab, JS_slidebox;或者使用 data-* 挂钩JS功能
288310

289311
**Bad example:**
290312

@@ -351,3 +373,4 @@ span { ... }
351373
### Thanks
352374

353375
Heavily inspired by [Idiomatic CSS](https://github.com/necolas/idiomatic-css) and the [GitHub Styleguide](http://github.com/styleguide). Made with all the love in the world by [@mdo](http://twitter.com/mdo).
376+

0 commit comments

Comments
 (0)