Elements are things inside your component.
元素就是在你的元件中的物件
Each component may have elements. They should have classes that are only one word.
每個元件或許有數個元素。它們的 class 應該只能用 一個單字 來命名。
.search-form {
> .field { /* ... */ }
> .action { /* ... */ }
}
Prefer to use the >
child selector whenever possible. This prevents bleeding through nested components, and performs better than descendant selectors.
盡可能使用 >
來指定子選擇器。 這可以防止在巢狀元件中發生滲漏的情況,且效能比後代選擇器要來得好。
.article-card {
.title { /* okay */ }
> .author { /* ✓ better */ }
}
For those that need two or more words, concatenate them without dashes or underscores.
對於那些需要兩個或更多的單字,不用加 dash (-
) 或底線將它們連接起來。
.profile-box {
> .firstname { /* ... */ }
> .lastname { /* ... */ }
> .avatar { /* ... */ }
}
Use classnames whenever possible. Tag selectors are fine, but they may come at a small performance penalty and may not be as descriptive.
盡可能使用 class 名稱。 標籤選擇器雖然可以,但他們可能會造成一些效能上的損失及不具有可描述性。
.article-card {
> h3 { /* ✗ avoid */ }
> .name { /* ✓ better */ }
}
Not all elements should always look the same. Variants can help.
並非所有元素總是看起來要是一樣的。變數可以提供幫助。
Continue 繼續 →