Skip to content

Commit eb6e4f4

Browse files
committed
translate to traditional chinese
patch list
1 parent f06502b commit eb6e4f4

File tree

1 file changed

+125
-110
lines changed

1 file changed

+125
-110
lines changed

README.md

Lines changed: 125 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
# Airbnb CSS / Sass Styleguide
1+
# Airbnb CSS / Sass 指南
22

3-
*A mostly reasonable approach to CSS and Sass*
3+
*用更合理的方式寫 CSS Sass*
44

5-
## Table of Contents
5+
翻譯自 [Airbnb CSS / Sass Styleguide](https://github.com/airbnb/css)
66

7-
1. [Terminology](#terminology)
8-
- [Rule Declaration](#rule-declaration)
9-
- [Selectors](#selectors)
10-
- [Properties](#properties)
7+
## 目錄
8+
9+
1. [術語](#terminology)
10+
- [規則宣告](#rule-declaration)
11+
- [選擇器](#selectors)
12+
- [屬性](#properties)
1113
1. [CSS](#css)
12-
- [Formatting](#formatting)
13-
- [Comments](#comments)
14-
- [OOCSS and BEM](#oocss-and-bem)
15-
- [ID Selectors](#id-selectors)
16-
- [JavaScript hooks](#javascript-hooks)
17-
- [Border](#border)
14+
- [格式](#formatting)
15+
- [註解](#comments)
16+
- [OOCSS BEM](#oocss-and-bem)
17+
- [ID 選擇氣](#id-selectors)
18+
- [JavaScript 掛鉤](#javascript-hooks)
19+
- [邊框](#border)
1820
1. [Sass](#sass)
19-
- [Syntax](#syntax)
20-
- [Ordering](#ordering-of-property-declarations)
21-
- [Variables](#variables)
21+
- [語法](#syntax)
22+
- [排序](#ordering-of-property-declarations)
23+
- [變數](#variables)
2224
- [Mixins](#mixins)
23-
- [Extend directive](#extend-directive)
24-
- [Nested selectors](#nested-selectors)
25-
1. [Translation](#translation)
25+
- [擴展指令](#extend-directive)
26+
- [巢狀選擇器](#nested-selectors)
2627

27-
## Terminology
28+
<a name="terminology"></a>
29+
## 術語
2830

29-
### Rule declaration
31+
<a name="rule-declaration"></a>
32+
### 規則宣告
3033

31-
A “rule declaration” is the name given to a selector (or a group of selectors) with an accompanying group of properties. Here's an example:
34+
我們把包含一組屬性的一個(或多個組合的)選擇器稱之為 “規則宣告”。舉個例子:
3235

3336
```css
3437
.listing {
@@ -37,9 +40,10 @@ A “rule declaration” is the name given to a selector (or a group of selector
3740
}
3841
```
3942

40-
### Selectors
43+
<a name="selectors"></a>
44+
### 選擇器
4145

42-
In a rule declaration, “selectors” are the bits that determine which elements in the DOM tree will be styled by the defined properties. Selectors can match HTML elements, as well as an element's class, ID, or any of its attributes. Here are some examples of selectors:
46+
在規則宣告中,“選擇器” 決定了 DOM 樹中的哪些元素將被定義的屬性所修飾。選擇器可以配對 HTML 元素,也可以配對一个元素的類別名稱、ID, 或者元素擁有的屬性。以下是選擇器的例子:
4347

4448
```css
4549
.my-element-class {
@@ -51,9 +55,10 @@ In a rule declaration, “selectors” are the bits that determine which element
5155
}
5256
```
5357

54-
### Properties
58+
<a name="properties"></a>
59+
### 屬性
5560

56-
Finally, properties are what give the selected elements of a rule declaration their style. Properties are key-value pairs, and a rule declaration can contain one or more property declarations. Property declarations look like this:
61+
最後,屬性決定了規則宣告裡面被選擇的元素將會得到何種樣式。屬性以 key-value pairs 形式存在,一個規則宣告可以包含一或多個屬性宣告。屬性宣告如下:
5762

5863
```css
5964
/* some selector */ {
@@ -62,19 +67,20 @@ Finally, properties are what give the selected elements of a rule declaration th
6267
}
6368
```
6469

70+
<a name="css"></a>
6571
## CSS
6672

67-
### Formatting
73+
<a name="formatting"></a>
74+
### 格式
6875

69-
* Use soft tabs (2 spaces) for indentation
70-
* Prefer dashes over camelCasing in class names.
71-
- Underscores and PascalCasing are okay if you are using BEM (see [OOCSS and BEM](#oocss-and-bem) below).
72-
* Do not use ID selectors
73-
* When using multiple selectors in a rule declaration, give each selector its own line.
74-
* Put a space before the opening brace `{` in rule declarations
75-
* In properties, put a space after, but not before, the `:` character.
76-
* Put closing braces `}` of rule declarations on a new line
77-
* Put blank lines between rule declarations
76+
* 使用 soft tabs (兩個空格)作為縮排。
77+
* 類別名稱建議使用 dashes 代替 camelCasing。如果你使用 BEM,也可以使用底線或 PascalCasing(參考下面的 [OOCSS 和 BEM](#oocss-and-bem))。
78+
* 不要使用 ID 選擇器。
79+
* 在一個規則宣告中,若同時使用多個選擇器時,讓每個選擇器各佔一行。
80+
* 在規則宣告的左大括弧 `{` 前加上一個空格。
81+
* 在屬性設定的冒號 `:` 後面加上一個空格,前面不要加空格。
82+
* 讓規則宣告的結束右大括弧 `}` 獨自一行。
83+
* 每個規則宣告之間用空白行隔開。
7884

7985
**Bad**
8086

@@ -105,85 +111,86 @@ Finally, properties are what give the selected elements of a rule declaration th
105111
}
106112
```
107113

108-
### Comments
114+
<a name="comments"></a>
115+
### 註解
116+
117+
* 建議使用單行註解 (在 Sass 中是 `//`) 代替區塊註解。
118+
* 建議讓註解獨自一行,避免行末註解。
119+
* 為沒有文件紀錄的程式碼寫上詳細註解,比如:
120+
- z-index 的使用情境
121+
- 兼容性處理或是針對特定瀏覽器的特殊寫法
109122

110-
* Prefer line comments (`//` in Sass-land) to block comments.
111-
* Prefer comments on their own line. Avoid end-of-line comments.
112-
* Write detailed comments for code that isn't self-documenting:
113-
- Uses of z-index
114-
- Compatibility or browser-specific hacks
123+
<a name="oocss-and-bem"></a>
124+
### OOCSS 和 BEM
115125

116-
### OOCSS and BEM
126+
由於以下原因,我們鼓勵使用 OOCSS BEM 的某些組合:
117127

118-
We encourage some combination of OOCSS and BEM for these reasons:
128+
* 可使 CSS 與 HTML 之間的關係更清晰且嚴謹。
129+
* 可幫助我們創建出可重用、可重組的元件。
130+
* 可以減少巢狀宣告,並降低特定性。
131+
* 可以幫助我們創建出可擴展的樣式。
119132

120-
* It helps create clear, strict relationships between CSS and HTML
121-
* It helps us create reusable, composable components
122-
* It allows for less nesting and lower specificity
123-
* It helps in building scalable stylesheets
133+
**OOCSS**,也就是 “Object Oriented CSS(物件導向的CSS)”,是一種寫 CSS 的方法,中心哲學就是鼓勵你把樣式表看成“物件”的集合:利用擁有可重用、可重組特性的程式碼,使你可以在整個網站中多次使用。
124134

125-
**OOCSS**, or “Object Oriented CSS”, is an approach for writing CSS that encourages you to think about your stylesheets as a collection of “objects”: reusable, repeatable snippets that can be used independently throughout a website.
135+
参考资料:
126136

127-
* Nicole Sullivan's [OOCSS wiki](https://github.com/stubbornella/oocss/wiki)
128-
* Smashing Magazine's [Introduction to OOCSS](http://www.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/)
137+
* Nicole Sullivan [OOCSS wiki](https://github.com/stubbornella/oocss/wiki)
138+
* Smashing Magazine [Introduction to OOCSS](http://www.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/)
129139

130-
**BEM**, or “Block-Element-Modifier”, is a _naming convention_ for classes in HTML and CSS. It was originally developed by Yandex with large codebases and scalability in mind, and can serve as a solid set of guidelines for implementing OOCSS.
140+
**BEM**,也就是 “Block-Element-Modifier”,是一種用於 HTML CSS 類別名稱的_命名约定_。BEM 最初由 Yandex 所提出,他們擁有大量的程式庫以及延展性。可以作為一套遵循 OOCSS 的實作參考規範。
131141

132-
* CSS Trick's [BEM 101](https://css-tricks.com/bem-101/)
133-
* Harry Roberts' [introduction to BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/)
142+
* CSS Trick [BEM 101](https://css-tricks.com/bem-101/)
143+
* Harry Roberts [introduction to BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/)
134144

135-
We recommend a variant of BEM with PascalCased “blocks”, which works particularly well when combined with components (e.g. React). Underscores and dashes are still used for modifiers and children.
145+
建議使用搭配 PascalCased "區塊"的變形 BEM,在與元件結合操作時特別適用 (e.g. React)。底線與破折號依然用在修飾符與子元件。
136146

137-
**Example**
147+
**範例**
138148

139-
```jsx
140-
// ListingCard.jsx
141-
function ListingCard() {
142-
return (
143-
<article class="ListingCard ListingCard--featured">
149+
```html
150+
<article class="listing-card listing-card--featured">
144151

145-
<h1 class="ListingCard__title">Adorable 2BR in the sunny Mission</h1>
152+
<h1 class="listing-card__title">Adorable 2BR in the sunny Mission</h1>
146153

147-
<div class="ListingCard__content">
148-
<p>Vestibulum id ligula porta felis euismod semper.</p>
149-
</div>
154+
<div class="listing-card__content">
155+
<p>Vestibulum id ligula porta felis euismod semper.</p>
156+
</div>
150157

151-
</article>
152-
);
153-
}
158+
</article>
154159
```
155160

156161
```css
157-
/* ListingCard.css */
158-
.ListingCard { }
159-
.ListingCard--featured { }
160-
.ListingCard__title { }
161-
.ListingCard__content { }
162+
.listing-card { }
163+
.listing-card--featured { }
164+
.listing-card__title { }
165+
.listing-card__content { }
162166
```
163167

164-
* `.ListingCard` is the “block” and represents the higher-level component
165-
* `.ListingCard__title` is an “element” and represents a descendant of `.ListingCard` that helps compose the block as a whole.
166-
* `.ListingCard--featured` is a “modifier” and represents a different state or variation on the `.ListingCard` block.
168+
* `.listing-card` 是一個區塊(block),代表高層次的元件。
169+
* `.listing-card__title` 是一個元素(element),它屬於 `.listing-card` 的一部份,因此區塊是由元素所組成。
170+
* `.listing-card--featured` 是一個修飾符(modifier),表示這個區塊與 `.listing-card` 有不同的狀態或變化。
167171

168-
### ID selectors
172+
<a name="id-selectors"></a>
173+
### ID 選擇器
169174

170-
While it is possible to select elements by ID in CSS, it should generally be considered an anti-pattern. ID selectors introduce an unnecessarily high level of [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) to your rule declarations, and they are not reusable.
175+
雖然在 CSS 中,你可以透過 ID 選擇元素,但這種作法應該列為 anti-patternID 選擇器為你的規則宣告帶來了不必要的高[優先權級](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity),而且 ID 選擇器不可重用。
171176

172-
For more on this subject, read [CSS Wizardry's article](http://csswizardry.com/2014/07/hacks-for-dealing-with-specificity/) on dealing with specificity.
177+
想要了解更多關於這個主題的內容,請參考 [CSS Wizardry 的文章](http://csswizardry.com/2014/07/hacks-for-dealing-with-specificity/),內有關於如何處理優先權級的文章。
173178

174-
### JavaScript hooks
179+
<a name="javascript-hooks"></a>
180+
### JavaScript 掛鉤
175181

176-
Avoid binding to the same class in both your CSS and JavaScript. Conflating the two often leads to, at a minimum, time wasted during refactoring when a developer must cross-reference each class they are changing, and at its worst, developers being afraid to make changes for fear of breaking functionality.
182+
避免在 CSS 和 Javascript 中綁定相同的類別。否則開發者在進行重構時容易出現問題,輕則浪費時間在相互對照尋找要修改的類別名稱,嚴重則因為害怕破壞功能而不敢進行更動。
177183

178-
We recommend creating JavaScript-specific classes to bind to, prefixed with `.js-`:
184+
我們推薦在創建用於 JavaScript 的類別名稱時,添加 `.js-` 前綴:
179185

180186
```html
181187
<button class="btn btn-primary js-request-to-book">Request to Book</button>
182188
```
183189

184-
### Border
190+
<a name="border"></a>
191+
### 邊框
185192

186-
Use `0` instead of `none` to specify that a style has no border.
193+
在定義無邊框樣式時,使用 `0` 代替 `none`
187194

188195
**Bad**
189196

@@ -201,18 +208,21 @@ Use `0` instead of `none` to specify that a style has no border.
201208
}
202209
```
203210

211+
<a name="sass"></a>
204212
## Sass
205213

206-
### Syntax
214+
<a name="syntax"></a>
215+
### 語法
207216

208-
* Use the `.scss` syntax, never the original `.sass` syntax
209-
* Order your regular CSS and `@include` declarations logically (see below)
217+
* 使用 `.scss` 的語法,不使用 `.sass` 原本的語法。
218+
* CSS `@include` 宣告依照以下邏輯排序(詳見下文)
210219

211-
### Ordering of property declarations
220+
<a name="ordering-of-property-declarations"></a>
221+
### 屬性宣告的排序
212222

213-
1. Property declarations
223+
1. 屬性宣告
214224

215-
List all standard property declarations, anything that isn't an `@include` or a nested selector.
225+
列出除了 `@include` 與 巢狀選擇器之外的所有屬性宣告。
216226

217227
```scss
218228
.btn-green {
@@ -222,9 +232,9 @@ Use `0` instead of `none` to specify that a style has no border.
222232
}
223233
```
224234

225-
2. `@include` declarations
235+
2. `@include` 宣告
226236

227-
Grouping `@include`s at the end makes it easier to read the entire selector.
237+
接著再放入 `@include`,這樣可以提高整個選擇器的可讀性。
228238

229239
```scss
230240
.btn-green {
@@ -235,9 +245,9 @@ Use `0` instead of `none` to specify that a style has no border.
235245
}
236246
```
237247

238-
3. Nested selectors
248+
3. 巢狀選擇器
239249

240-
Nested selectors, _if necessary_, go last, and nothing goes after them. Add whitespace between your rule declarations and nested selectors, as well as between adjacent nested selectors. Apply the same guidelines as above to your nested selectors.
250+
_如果有必要_用到巢狀選擇器,把它們放到最後。此外,規則宣告與巢狀選擇器之間要加上空白行。而巢狀選擇器中的內容也要遵循上述指引。
241251

242252
```scss
243253
.btn {
@@ -251,21 +261,25 @@ Use `0` instead of `none` to specify that a style has no border.
251261
}
252262
```
253263

254-
### Variables
264+
<a name="variables"></a>
265+
### 變數
255266

256-
Prefer dash-cased variable names (e.g. `$my-variable`) over camelCased or snake_cased variable names. It is acceptable to prefix variable names that are intended to be used only within the same file with an underscore (e.g. `$_my-variable`).
267+
變數名稱建議使用破折號(例如 `$my-variable`)代替 camelCased snake_cased 風格。可以在變數名稱之前添加底線前綴符,用以代表此變數只使用於當前文件。(例如 `$_my-variable`)。
257268

269+
<a name="mixins"></a>
258270
### Mixins
259271

260-
Mixins should be used to DRY up your code, add clarity, or abstract complexity--in much the same way as well-named functions. Mixins that accept no arguments can be useful for this, but note that if you are not compressing your payload (e.g. gzip), this may contribute to unnecessary code duplication in the resulting styles.
272+
Mixins 可幫助你的代碼遵循 DRY 原則(Don't Repeat Yourself)、增加清晰度或抽象畫複雜度。這與使用良好命名的函數有異曲同工之妙。Mixins 可以不接收參數,但要注意的是,如果你不壓縮 payloade.g. gzip),可能會導致最終的樣式表包含不必要的重複程式碼。
261273

262-
### Extend directive
274+
<a name="extend-directive"></a>
275+
### 擴展指令
263276

264-
`@extend` should be avoided because it has unintuitive and potentially dangerous behavior, especially when used with nested selectors. Even extending top-level placeholder selectors can cause problems if the order of selectors ends up changing later (e.g. if they are in other files and the order the files are loaded shifts). Gzipping should handle most of the savings you would have gained by using `@extend`, and you can DRY up your stylesheets nicely with mixins.
277+
應避免使用 `@extend` 指令,因為他並不直觀,且具有潛在風險,特別是用在巢狀選擇器時。即使是針對在最上層的佔位符選擇器使用擴展,如果選擇器的順序最終會改變,也可能會導致問題。(比如,擴展的選擇器存在於別份文件,而其加載順序發生變化)。使用 `@extend` 所獲得的大部分優化效果,透過 gzip 縮就已經幫你做到了,而你可以再透過 mixin 來讓你的樣式表更符合 DRY 原則。
265278

266-
### Nested selectors
279+
<a name="nested-selectors"></a>
280+
### 巢狀選擇器
267281

268-
**Do not nest selectors more than three levels deep!**
282+
**請不要讓巢狀選擇器超過三層!**
269283

270284
```scss
271285
.page-container {
@@ -277,24 +291,25 @@ Mixins should be used to DRY up your code, add clarity, or abstract complexity--
277291
}
278292
```
279293

280-
When selectors become this long, you're likely writing CSS that is:
294+
當上述情況發生時,你也許是這樣寫 CSS 的:
281295

282-
* Strongly coupled to the HTML (fragile) *—OR—*
283-
* Overly specific (powerful) *—OR—*
284-
* Not reusable
296+
* HTML 強耦合的(也是脆弱)*—或者*
297+
* 過於針對與具體(強大)*—或者*
298+
* 沒有重複使用程式碼
285299

286300

287-
Again: **never nest ID selectors!**
301+
再說一遍: **永遠不要巢狀 ID 選擇器!**
288302

289-
If you must use an ID selector in the first place (and you should really try not to), they should never be nested. If you find yourself doing this, you need to revisit your markup, or figure out why such strong specificity is needed. If you are writing well formed HTML and CSS, you should **never** need to do this.
303+
如果你真的必須使用 ID 選擇器(你真的不應該...),那他們也不該是巢狀的。如果你發現你正在這樣做,那你可能需要重新檢查你的 markup,或是說明這樣做的原因。如果你想要寫出良好風格的 HTML CSS,你絕對****應該這麼做。
290304

291-
## Translation
305+
## 翻譯
292306

293-
This style guide is also available in other languages:
307+
這份 style guide 也被翻譯成以下語言:
294308

309+
- ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese (Traditional)**: [ArvinH/css-style-guide](https://github.com/ArvinH/css-style-guide)
295310
- ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [Zhangjd/css-style-guide](https://github.com/Zhangjd/css-style-guide)
296311
- ![ja](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [nao215/css-style-guide](https://github.com/nao215/css-style-guide)
297312
- ![ko](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [CodeMakeBros/css-style-guide](https://github.com/CodeMakeBros/css-style-guide)
298313
- ![PT-BR](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Portuguese**: [felipevolpatto/css-style-guide](https://github.com/felipevolpatto/css-style-guide)
299314
- ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [Nekorsis/css-style-guide](https://github.com/Nekorsis/css-style-guide)
300-
- ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Spanish**: [ismamz/guia-de-estilo-css](https://github.com/ismamz/guia-de-estilo-css)
315+
- ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Spanish**: [ismamz/guia-de-estilo-css](https://github.com/ismamz/guia-de-estilo-css)

0 commit comments

Comments
 (0)