Article title
259 |3 votes
260 |├── images
├── layouts.png
├── component-example.png
├── component-nesting.png
├── component-elements.png
└── component-modifiers.png
├── sketch
└── illustrations.sketch
├── History.md
└── Readme.md
/images/layouts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tscanlin/rscss/master/images/layouts.png
--------------------------------------------------------------------------------
/images/component-example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tscanlin/rscss/master/images/component-example.png
--------------------------------------------------------------------------------
/images/component-nesting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tscanlin/rscss/master/images/component-nesting.png
--------------------------------------------------------------------------------
/sketch/illustrations.sketch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tscanlin/rscss/master/sketch/illustrations.sketch
--------------------------------------------------------------------------------
/images/component-elements.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tscanlin/rscss/master/images/component-elements.png
--------------------------------------------------------------------------------
/images/component-modifiers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tscanlin/rscss/master/images/component-modifiers.png
--------------------------------------------------------------------------------
/History.md:
--------------------------------------------------------------------------------
1 | ## v1.1.0 - 2015-02-10
2 |
3 | Child selectors are now the preferred convention for styling elements. (#2)
4 |
5 | ## v1.0.0 - 2015-01-30
6 |
7 | Initial version.
8 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | RSCSS
2 | =====
3 |
4 | **Reasonable Standard* for CSS Stylesheet Structure.**
5 |
6 | :construction: This document is a work in progress. See the [changelog](History.md) for summaries of revisions.
7 |
8 | (`*`: or **S** can also stand for "suggestions")
9 |
10 |
11 |
12 | Problem
13 | -------
14 |
15 | Any CSS greater than 1000 lines will get unwieldy. You'll eventually run into these common pitfalls:
16 |
17 | * "What does this class mean?"
18 | * "Is this class still being used?"
19 | * "If I make a new class `green`, will there be a clash?"
20 |
21 |
22 |
23 | Structure
24 | ---------
25 |
26 | ### Think in components
27 |
28 | 
29 |
30 | Think of each piece of your UI is an individual "component." Components will be named with **at least two words**, separated by a dash. Examples of a component:
31 |
32 | * A like button (`.like-button`)
33 | * A search form (`.search-form`)
34 | * A news article card (`.article-card`)
35 |
36 | ### Elements
37 |
38 | 
39 |
40 | **Naming:** Each component may have elements. They should have classes that are only **one word**.
41 |
42 | ```scss
43 | .search-form {
44 | > .field { /* ... */ }
45 | > .action { /* ... */ }
46 | }
47 | ```
48 |
49 | **Selectors:** Prefer to use the `>` child selector whenever possible. This prevents bleeding through nested components, and performs better than descendant selectors.
50 |
51 | ```scss
52 | .article-card {
53 | .title { /* okay */ }
54 | > .author { /* ✓ better */ }
55 | }
56 | ```
57 |
58 | **On multiple words:** For those that need two or more words, concatenate them without dashes or underscores.
59 |
60 | ```scss
61 | .profile-box {
62 | > .firstname { /* ... */ }
63 | > .lastname { /* ... */ }
64 | > .avatar { /* ... */ }
65 | }
66 | ```
67 |
68 | **Avoid tag selectors:** use classnames whenever possible. Tag selectors are fine, but they may come at a small performance penalty and may not be as descriptive.
69 |
70 | ```scss
71 | .article-card {
72 | > h3 { /* ... */ }
73 | > .name { /* ✓ better */ }
74 | }
75 | ```
76 |
77 | ### Variants
78 |
79 | 
80 |
81 | Components may have variants. Their classes will be prefixed by a dash (`-`).
82 |
83 | ```scss
84 | .like-button {
85 | &.-wide { /* ... */ }
86 | &.-short { /* ... */ }
87 | &.-disabled { /* ... */ }
88 | }
89 | ```
90 |
91 | Elements may also have variants.
92 |
93 | ```scss
94 | .shopping-card {
95 | > .title { /* ... */ }
96 | > .title.-small { /* ... */ }
97 | }
98 | ```
99 |
100 | Why a dash? Because:
101 |
102 | * it prevents ambiguity with elements
103 | * a CSS class can only start with a letter, `_` or `-`
104 | * dashes are easier to type than underscores
105 | * it kind of resembles switches in UNIX commands (`gcc -O2 -Wall -emit-last`)
106 |
107 | ### Nested components
108 |
109 | 
110 |
111 | Sometimes it's necessary to nest components.
112 |
113 | ```html
114 |
3 votes
260 |