1
1
## CSS
2
- These guidelines have been assembled following an examination of emerging practices, ideas and existing styleguides, namely:
2
+ 這份準則是透過檢視一些新興的程式實作、想法、以及現有的編碼規範所集思廣益而成,並引用以下清單中所使用的概念:
3
3
4
4
1 . [ OOCSS Code Standards] ( https://github.com/stubbornella/oocss-code-standards )
5
5
2 . [ Oneweb Style Guide] ( https://github.com/nternetinspired/OneWeb/blob/master/STYLEGUIDE.md )
6
6
3 . [ Idiomatic CSS] ( https://github.com/necolas/idiomatic-css )
7
7
8
8
9
- ## Commenting
9
+ ## 註解
10
+
11
+ ### 主要段落
12
+ 主要的程式碼段落必須以完整的註解區塊作為開頭,例如:
10
13
11
- ### Major sections
12
- Major code sections should be named in caps and within a full comment block, eg:
13
14
``` css
14
15
/* ==========================================================================
15
16
PRIMARY NAVIGATION
16
17
========================================================================== */
17
18
```
18
19
19
- ### Sub sections
20
- Subsections should be normally cased and within an open comment block.
20
+ ### 次要段落
21
+ 次要段落須以開放式的註解區塊為開頭:
22
+
21
23
``` css
22
24
/* Mobile navigation
23
25
========================================================================== */
24
26
```
25
27
26
- ### Verbose comments
28
+ ### 文字註解
27
29
``` css
28
30
/* *
29
- * Short description using Doxygen-style comment format
31
+ * 短的註解描述使用 Doxygen 風格的註解格式
30
32
*
31
33
* The first sentence of the long description starts here and continues on this
32
34
* line for a while finally concluding here at the end of this paragraph.
33
35
*
34
- * The long description is ideal for more detailed explanations and
35
- * documentation. It can include example HTML, URLs, or any other information
36
- * that is deemed necessary or useful.
36
+ * 長的註解描述很適合做詳細的解釋與說明。如果有需要,可以使用 HTML、URLs 或其他資訊作為範例。
37
37
*
38
38
* @tag This is a tag named 'tag'
39
39
*
40
- * TODO: This is a todo statement that describes an atomic task to be completed
41
- * at a later date. It wraps after 80 characters and following lines are
42
- * indented by 2 spaces.
40
+ * TODO: 這是一個註解區塊中 todo 的範例,描述之後需要被完成的項目。
41
+ * 一行應小於 80 個字元,換行之後須以兩個空白作為縮排開頭
43
42
*/
44
43
```
45
44
46
- ### Basic comments
45
+ ### 基本註解方式
47
46
``` css
48
47
/* Basic comment */
49
48
```
50
49
51
- ### Uncompiled LESS/Scss comments
50
+ ### 未編譯的 LESS/Scss 註解
52
51
``` css
53
- // These are stripped on compile.
52
+ // 這段註解在編譯的時候會被移除
54
53
```
55
54
56
- ## Class naming
57
- Use dashes to create compound class names:
55
+ ## Class 命名方式
56
+ 使用破折號 (-) 來處理復合式命名:
58
57
59
58
```css
60
- /* Good - use dashes */
59
+ /* 正確 - 使用破折號 */
61
60
.compound-class-name {…}
62
61
63
- /* Bad - uses underscores */
62
+ /* 錯誤 - 使用底線 */
64
63
.compound_class_name {…}
65
64
66
- /* Bad - uses camelCase */
65
+ /* 錯誤 - 使用駝峰式命名 */
67
66
.compoundClassName {…}
68
67
69
- /* Bad - does not use seperators */
68
+ /* 錯誤 - 不使用符號分隔 */
70
69
.compoundclassname {…}
71
70
```
72
71
73
- ### Indentation
74
- Rules should be indented one tab (equal to 4 spaces):
72
+ ### 縮排
73
+ 須以一個 tab 來縮排 (等於 4 個空白)
75
74
76
75
``` css
77
- /* Good */
76
+ /* 正確 */
78
77
.example {
79
78
color : #000 ;
80
79
visibility : hidden ;
81
80
}
82
81
83
- /* Bad - all on one line */
82
+ /* 錯誤 - 寫在同一行 */
84
83
.example {color : #000 ; visibility : hidden ;}
85
84
```
86
85
86
+ LESS/Scss 也應該正確被縮排寫成巢狀,其子選擇器還有樣式規則都應該縮排。巢狀的規則須以一空行作為間隔:
87
87
LESS/Scss should also be nested , with child selectors and rules indented again. Nested rules should also be spaced by one line:
88
88
89
89
``` css
90
- /* Good */
90
+ /* 正確 */
91
91
.example {
92
92
93
93
> li {
@@ -101,7 +101,7 @@ LESS/Scss should also be nested , with child selectors and rules indented again.
101
101
}
102
102
103
103
}
104
- /* Bad - nested rules not indented */
104
+ /* 錯誤 - 巢狀的樣式沒有正確縮排 */
105
105
.example {
106
106
107
107
> li {
@@ -115,7 +115,7 @@ LESS/Scss should also be nested , with child selectors and rules indented again.
115
115
}
116
116
117
117
}
118
- /* Bad - nested rules not spaced */
118
+ /* 錯誤 - 巢狀的規則沒有以一空行作為間隔 */
119
119
.example {
120
120
> li {
121
121
float : none ;
@@ -127,93 +127,94 @@ LESS/Scss should also be nested , with child selectors and rules indented again.
127
127
}
128
128
```
129
129
130
- ### Alignment
131
- The opening brace must be on the same line as the last selector and preceded by a space. The closing brace must be on its own line after the last property and be indented to the same level as the opening brace.
130
+ ### 對齊
131
+ 左大括號必須跟選擇器位於同一行,並前綴一空白字元。右大括號須存在於最後一個屬性規則之後並獨立於新的一行,且應與左大括號處於相同的縮排。
132
132
133
133
``` css
134
- /* Good */
134
+ /* 正確 */
135
135
.example {
136
136
color : #fff ;
137
137
}
138
138
139
- /* Bad - closing brace is in the wrong place */
139
+ /* 錯誤 - 右大括號的位置錯了,沒有正確縮排 */
140
140
.example {
141
141
color : #fff ;
142
142
}
143
143
144
- /* Bad - opening brace missing space */
144
+ /* 錯誤 - 左大括號之前沒有空白 */
145
145
.example {
146
146
color : #fff ;
147
147
}
148
148
```
149
149
150
- ### Property Format
151
- Each property must be on its own line and indented one level. There should be no space before the colon and one space after. All properties must end with a semicolon.
150
+ ### 樣式屬性格式
151
+ 每一個屬性都應該存在獨立的一行,並縮排一個層級。冒號之前不應該有空白字元,但須後綴一空白字元。所有的樣式屬性須以分號 (;) 作為結尾。
152
152
153
153
``` css
154
- /* Good */
154
+ /* 正確 */
155
155
.example {
156
156
background : black ;
157
157
color : #fff ;
158
158
}
159
159
160
- /* Bad - missing spaces after colons */
160
+ /* 錯誤 - 冒號後面沒有後綴空白 */
161
161
.example {
162
162
background :black ;
163
163
color :#fff ;
164
164
}
165
165
166
- /* Bad - missing last semicolon */
166
+ /* 錯誤 - 沒有以分號作為結尾 */
167
167
.example {
168
168
background : black ;
169
169
color : #fff
170
170
}
171
171
```
172
172
173
- ### HEX values
174
- HEX values must be declared in lowercase and shorthand:
173
+ ### HEX 值
174
+ HEX 值應該使用小寫並以最小縮寫宣告:
175
+
175
176
``` css
176
- /* Good */
177
+ /* 正確 */
177
178
.example {
178
179
color : #eee ;
179
180
}
180
181
181
- /* Bad */
182
+ /* 錯誤 */
182
183
.example {
183
184
color : #EEEEEE ;
184
185
}
185
186
```
186
187
187
- ### Attribute selectors
188
- Always use double quotes around attribute selectors.
188
+ ### HTML 屬性選擇器
189
+ 屬性選擇器須以雙引號包含。
189
190
190
191
``` css
191
- /* Good */
192
+ /* 正確 */
192
193
input [type = " button" ] {
193
194
...
194
195
}
195
196
196
- /* Bad - missing quotes */
197
+ /* 錯誤 - 沒有雙引號 */
197
198
input [type = button ] {
198
199
...
199
200
}
200
201
201
- /* Bad - using single quote */
202
+ /* 錯誤 - 使用單引號 */
202
203
input [type = ' button' ] {
203
204
...
204
205
}
205
206
```
206
207
207
- ### Zero value units
208
- Zero values should not carry units.
208
+ ### 零值的單位
209
+ 零值不應該使用單位。
209
210
210
211
``` css
211
- /* Good */
212
+ /* 正確 */
212
213
.example {
213
214
padding : 0 ;
214
215
}
215
216
216
- /* Bad - uses units */
217
+ /* 錯誤 - 使用單位 */
217
218
.example {
218
219
padding : 0px ;
219
220
}
0 commit comments