You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-84Lines changed: 84 additions & 84 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,34 +1,34 @@
1
1
# Airbnb CSS / Sass Styleguide
2
2
3
-
*A mostly reasonable approach to CSS and Sass*
3
+
*Một cách tiếp cận hợp lý nhất với CSS và SASS*
4
4
5
-
## Table of Contents
5
+
## Mục lục
6
6
7
-
1.[Terminology](#terminology)
8
-
-[Rule Declaration](#rule-declaration)
7
+
1.[Thuật ngữ](#terminology)
8
+
-[Khai báo](#khai-báo)
9
9
-[Selectors](#selectors)
10
-
-[Properties](#properties)
10
+
-[Thuộc tính](#thuộc-tính)
11
11
1.[CSS](#css)
12
-
-[Formatting](#formatting)
13
-
-[Comments](#comments)
14
-
-[OOCSS and BEM](#oocss-and-bem)
12
+
-[Quy cách](#quy-cách)
13
+
-[Chú thích](#chú-thích)
14
+
-[OOCSS và BEM](#oocss-và-bem)
15
15
-[ID Selectors](#id-selectors)
16
16
-[JavaScript hooks](#javascript-hooks)
17
-
-[Border](#border)
17
+
-[Đường viền](#đường-viền)
18
18
1.[Sass](#sass)
19
-
-[Syntax](#syntax)
20
-
-[Ordering](#ordering-of-property-declarations)
21
-
-[Variables](#variables)
19
+
-[Cú pháp](#cú-pháp)
20
+
-[Thứ tự](##sắp-xếp-các-khai-báo-thuộc-tính)
21
+
-[Biến](#biến)
22
22
-[Mixins](#mixins)
23
-
-[Extend directive](#extend-directive)
24
-
-[Nested selectors](#nested-selectors)
23
+
-[Mở rộng directive](#extend-directive)
24
+
-[Selectors lồng nhau](##selectors-lồng-nhau)
25
25
1.[Translation](#translation)
26
26
27
-
## Terminology
27
+
## Thuật ngữ
28
28
29
-
### Rule declaration
29
+
### Khai báo
30
30
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:
31
+
Một "khai báo" là tên gọi của một selector (hoặc một nhóm các selectors) với một nhóm các thuộc tính. Dưới đây là ví dụ:
32
32
33
33
```css
34
34
.listing {
@@ -39,7 +39,7 @@ A “rule declaration” is the name given to a selector (or a group of selector
39
39
40
40
### Selectors
41
41
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:
42
+
Trong một khai báo, "selectors" là phần sẽ xác định xem phần tử nào trong DOM sẽ được style bởi các thuộc tính xác định. Selectors có thể tương ứng với các phần tử HTML, cũng như class hay ID của phần tử, hoặc bất kì thuộc tính nào của nó. Dưới đây là ví dụ về selectors:
43
43
44
44
```css
45
45
.my-element-class {
@@ -51,9 +51,9 @@ In a rule declaration, “selectors” are the bits that determine which element
51
51
}
52
52
```
53
53
54
-
### Properties
54
+
### Thuộc tính
55
55
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:
56
+
Thuộc tính là một cặp khóa-giá trị, và một khai báo có thể chứa một hoặc nhiều khai báo của thuộc tính. Cách khai báo của thuộc tính như sau:
57
57
58
58
```css
59
59
/* some selector */ {
@@ -64,19 +64,19 @@ Finally, properties are what give the selected elements of a rule declaration th
64
64
65
65
## CSS
66
66
67
-
### Formatting
67
+
### Quy cách
68
68
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
69
+
*Sử dụng soft tabs (2 dấu cách) cho khoảng cách thụt vào (indentation)
70
+
*Nên sử dụng dấu gạch ngang trong camelCasing của tên class.
71
+
-Dấu gạch dưới và PascalCasing sẽ không sao nếu bạn sử dụng BEM (xem[OOCSS and BEM](#oocss-and-bem)dưới đây).
72
+
*Không sử dụng ID Selectors.
73
+
*Khi sử dụng nhiều selector trong một khai báo, đặt mỗi selector trên một dòng kẻ.
74
+
*Trước dấu ngoặc nhọn `{`phải có một dấu cách trong khai báo.
75
+
*Trong thuộc tính, đặt một dấu cách đứng sau dấu hai chấm `:` .
76
+
*Đặt dấu đóng ngoặc nhọn `}`của một khai báo trên một dòng kẻ mới.
77
+
*Đặt một dòng kẻ trống giữa các khai báo.
78
78
79
-
**Bad**
79
+
**Không tốt**
80
80
81
81
```css
82
82
.avatar{
@@ -90,7 +90,7 @@ Finally, properties are what give the selected elements of a rule declaration th
90
90
}
91
91
```
92
92
93
-
**Good**
93
+
**Tốt**
94
94
95
95
```css
96
96
.avatar {
@@ -105,36 +105,36 @@ Finally, properties are what give the selected elements of a rule declaration th
105
105
}
106
106
```
107
107
108
-
### Comments
108
+
### Chú thích
109
109
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
110
+
*Nên dùng hai gạch (`//`) để đặt chú thích.
111
+
*Nên đặt chú thích trên một dòng kẻ riêng, không đặt ở cuối dòng kẻ.
112
+
*Viết chú thích chi tiết cho những dòng code mà không thể hiện được ý nghĩa rõ ràng khi đọc, ví dụ:
113
+
-Sử dụng z-index
114
+
-Khả năng tương thích và trình duyệt.
115
115
116
-
### OOCSS and BEM
116
+
### OOCSS và BEM
117
117
118
-
We encourage some combination of OOCSS and BEM for these reasons:
118
+
Chúng tôi khuyến khích một số sự kết hợp giữa OOCSS và BEM cho những lý do sau:
119
119
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
120
+
*Nó giúp tạo ra mối quan hệ chặt chẽ rõ ràng giữa CSS và HTML
121
+
*Nó giúp tạo ra những thành phần có thể tái sử dụng.
122
+
*Nó cho phép ít lồng nhau (nested) và giảm sự riêng biệt
123
+
*Nó giúp xây dựng stylesheets có khả năng mở rộng
124
124
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.
125
+
**OOCSS**, hay "CSS hướng đối tượng", là một phương pháp để viết code CSS mà khuyến khích bạn định hình stylesheets như một sự tập hợp của nhiều "đối tượng" (object): có thể tái sử dụng, có thể lặp lại độc lập xuyên suốt toàn bộ một trang web.
* Smashing Magazine's [Introduction to OOCSS](http://www.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/)
128
+
* Smashing Magazine's [Giới thiệu về OOCSS](http://www.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/)
129
129
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.
130
+
**BEM**, hay "Block-Element-Modifier", là một quy ước đặt tên cho classes trong HTML và CSS. Ban đầu nó được phát triển bởi Yandex với codebases lớn, có khả năng mở rộng, và có thể coi như một tập hợp của các hướng dẫn cho việc thực hiện OOCSS.
* Harry Roberts' [introduction to BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/)
133
+
* Harry Roberts' [Giới thiệt về BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/)
134
134
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.
135
+
Chúng tôi khuyến nghị sử dụng một biến thể của BEM với PascalCased "blocks", mà làm việc riêng biệt khá hiệu quả với các thành phần (components) (e.g. React). Dấu gạch dưới và gạch ngang vẫn được sử dụng cho thành phần modifiers và thành phần con.
136
136
137
-
**Example**
137
+
**Ví dụ**
138
138
139
139
```jsx
140
140
// ListingCard.jsx
@@ -161,29 +161,29 @@ function ListingCard() {
161
161
.ListingCard__content { }
162
162
```
163
163
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.
164
+
*`.ListingCard`là một "block" và đại diện cho thành phần cao hơn
165
+
*`.ListingCard__title`là một "phần tử" and biểu diễn như là một phần tử con của `.ListingCard`để tạo thành "block".
166
+
*`.ListingCard--featured`là một "modifier" và đại diện cho các trạng thái khác nhau hay các biến thể của`.ListingCard` block.
167
167
168
-
### ID selectors
168
+
### ID Selectors
169
169
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.
170
+
Trong khi có thể chọn các phần tử theo ID trong CSS, nó vẫn không nên được sử dụng. ID selectors giới thiệu một sự riêng biệt [sự riêng biệt](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)không cần thiết cho các khai báo của bạn và không thể tái sử dụng lại được.
171
171
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.
172
+
Để biết thêm về chủ đề này, đọc[CSS Wizardry's article](http://csswizardry.com/2014/07/hacks-for-dealing-with-specificity/) on dealing with specificity.
173
173
174
174
### JavaScript hooks
175
175
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.
176
+
Tránh việc binding cùng một class trong CSS và JavaScript. Việc làm đó có thể gây lãng phí thời gian ở mức nhẹ nhất khi lập trình viên phải kiểm tra chéo mỗi class khi thay đổi. Và trong trường hợp xấu nhất, lập trình viên có thể sẽ phải đối mặt với việc phá vỡ sự hoạt động của function.
177
177
178
-
We recommend creating JavaScript-specific classes to bind to, prefixed with`.js-`:
178
+
Chúng tôi khuyến nghị tạo ra các class riêng cho JavaScript để bind, tiền tố bắt đầu với`.js-`:
179
179
180
180
```html
181
181
<buttonclass="btn btn-primary js-request-to-book">Request to Book</button>
182
182
```
183
183
184
-
### Border
184
+
### Đường viền
185
185
186
-
Use `0`instead of`none`to specify that a style has no border.
186
+
Sử dụng `0`thay vì`none`để xác định rằng đối tượng này không có đường viền.
187
187
188
188
**Bad**
189
189
@@ -203,16 +203,16 @@ Use `0` instead of `none` to specify that a style has no border.
203
203
204
204
## Sass
205
205
206
-
### Syntax
206
+
### Cú pháp
207
207
208
-
*Use the`.scss`syntax, never the original `.sass` syntax
209
-
*Order your regular CSS and`@include`declarations logically (see below)
208
+
*Sử dụng`.scss`cú pháp, không bao giờ nên sử dụng cú pháp gốc của `.sass`
209
+
*Sắp xếp CSS và`@include`theo một logic (xem ở dưới)
210
210
211
-
### Ordering of property declarations
211
+
### Sắp xếp các khai báo thuộc tính
212
212
213
-
1.Property declarations
213
+
1.Khai báo thuộc tính
214
214
215
-
List all standard property declarations, anything that isn't an `@include`or a nested selector.
215
+
Khai báo toàn bộ thuộc tính cơ bản trước, những gì không phải là `@include`hay khai báo lồng (nested) selector.
216
216
217
217
```scss
218
218
.btn-green {
@@ -222,9 +222,9 @@ Use `0` instead of `none` to specify that a style has no border.
222
222
}
223
223
```
224
224
225
-
2. `@include` declarations
225
+
2. Khai báo `@include`
226
226
227
-
Grouping `@include`s at the end makes it easier to read the entire selector.
227
+
Nhóm `@include` ở cuối cùng để dễ dàng đọc toàn bộ selector.
228
228
229
229
```scss
230
230
.btn-green {
@@ -235,9 +235,9 @@ Use `0` instead of `none` to specify that a style has no border.
235
235
}
236
236
```
237
237
238
-
3. Nested selectors
238
+
3. Selectors lồng nhau
239
239
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.
240
+
Selectors lồng nhau, _nếu cần thiết_ , đặt ở cuối cùng, và không có gì viết sau nó nữa. Thêm khoảng trắng giữa khai báo và selector lồng nhau, cũng như giữa các phần tử con. Áp dụng toàn bộ hướng dẫn ở trên cho selector lồng nhau.
241
241
242
242
```scss
243
243
.btn {
@@ -251,21 +251,21 @@ Use `0` instead of `none` to specify that a style has no border.
251
251
}
252
252
```
253
253
254
-
### Variables
254
+
### Biến
255
255
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`).
256
+
Nên dùng gạch ngang giữa tên biến (e.g. `$my-variable`) thay vì camelCased or snake_cased. Nó cũng được phép dùng để đặt tiền tố cho tên biến nếu có ý định sử dụng trong cùng một file với dấu gạch dưới (e.g. `$_my-variable`).
257
257
258
258
### Mixins
259
259
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.
260
+
Mixins nên được sử dụng để không lặp lại các đoạn code giống nhau với phương châm (DRY - Don't-Repeat-Yourself) trong code của bạn, thêm sự rõ ràng, hoặc tách sự phức tạp - theo cách tương tự mà function được đặt tên. Mixins cho phép không có đối số có thể hữu ích cho việc này, nhưng chú ý rằng nếu bạn không nén lại(e.g. gzip), nó có thể đóng góp vào việc trùng lặpcode không cần thiết.
261
261
262
262
### Extend directive
263
263
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.
264
+
Nên tránh sử dụng `@extend` vì nó có một hành vi nguy hiểm tiềm tàng, đặc biệt khi sử dụng các selectors lồng nhau. Thậm chí mở rộng top-level placeholder selectors có thể gây ra vấn đề nếu thứ tự của selector kết thúc thay đổi sau đó (e.g. nếu họ đang ở một tệp tin khác, và thứ tự của các tệp tin được tải thay đổi.). Bạn có thể không lặp lại đoạn code của mình với mixins.
265
265
266
-
### Nested selectors
266
+
### Selectors lồng nhau
267
267
268
-
**Do not nest selectors more than three levels deep!**
268
+
**ĐỪNG selectors lồng hơn 3 cấp độ!**
269
269
270
270
```scss
271
271
.page-container {
@@ -277,20 +277,20 @@ Mixins should be used to DRY up your code, add clarity, or abstract complexity--
277
277
}
278
278
```
279
279
280
-
When selectors become this long, you're likely writing CSS that is:
280
+
Khi selectors trở nên như vậy, bạn có thể đã viết CSS theo:
281
281
282
-
* Strongly coupled to the HTML (fragile) *—OR—*
283
-
* Overly specific (powerful) *—OR—*
284
-
* Not reusable
282
+
*Liên kết chặt vớiHTML (dễ đổ vỡ) *hoặc*
283
+
*Quá cụ thể (powerful) *—hoặc—*
284
+
*Không tái sử dụng
285
285
286
286
287
-
Again: **never nest ID selectors!**
287
+
Lặp lại: **không bao giờ được lồng ID selectors!**
288
288
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.
289
+
Nếu bạn phải sử dụng ID selector ngay từ đầu (và bạn thực sự không nên làm thế), nó không bảo giờ nên được lồng nhau. Nếu bạn thấy mình làm điều này, bạn cần phải xem xét lạicodeHTML, hoặc tìm hiểu tại sao lại cần cụ thể đến như vậy. Nếu bạn đang viết HTMLvà CSS tốt, bạn **không bao giờ nên**cần phải làm điều này.
290
290
291
-
## Translation
291
+
## Dịch
292
292
293
-
This style guide is also available in other languages:
293
+
Styleguide này cũng có sẵn trong các ngôn ngữ khác:
0 commit comments