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
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: css/class-naming-conventions/readme.md
+11-16Lines changed: 11 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,7 +112,7 @@ These are used to modify components or subcomponents. They are always chained to
112
112
113
113
### Component modifiers that affect subcomponents
114
114
115
-
Sometimes a component modifier will affect its sub-components. There are a few methods you can use to accomplish this. Try to pick one and stick to it throughout the project, adding comments as needed.
115
+
Sometimes a component modifier will affect its sub-components. There are several methods you can use to accomplish this. As much as possible, stick to one method in your project.
116
116
117
117
```html
118
118
<divclass="c-blog-post c--featured">
@@ -124,10 +124,10 @@ Sometimes a component modifier will affect its sub-components. There are a few m
124
124
```
125
125
126
126
127
-
#### 1. Nested inside the component
127
+
#### 1. Styles grouped with modifier
128
128
Nest the `.c-component__sub-component` elements inside the `.c-component` SCSS.
129
129
130
-
This method works well when a modifier requires simple changes to a small number of sub-components.
130
+
This method allows you to quickly update or edit the styles for all elements affected by a modifier.
131
131
132
132
```scss
133
133
.c-blog-post {
@@ -141,11 +141,8 @@ This method works well when a modifier requires simple changes to a small number
141
141
}
142
142
```
143
143
144
+
*or*
144
145
145
-
#### 2. Root level as a selector chain
146
-
Use a selector chain with `.c-component.c--modifier`, and nest the `.c-component__sub-component` elements within it.
147
-
148
-
This method works especially well when a component has multiple modifiers or state classes that can be coupled with it.
149
146
150
147
```scss
151
148
.c-blog-post.c--featured {
@@ -157,23 +154,22 @@ This method works especially well when a component has multiple modifiers or sta
157
154
}
158
155
```
159
156
160
-
When using the above methods in larger files, add a comment to the `.c-component__sub-component`like so:
157
+
In larger files, adding a comment in the `.c-component__sub-component`notes can be helpful:
161
158
```scss
162
159
// Blog Post Title
163
160
// ---
164
161
//
165
-
// Modifier styles can be found in:
166
-
// .c-blog-post.c--featured
162
+
// Modified by .c-blog-post.c--featured
167
163
168
164
.c-blog-post__title {
169
165
...
170
166
}
171
167
```
172
168
173
-
#### 3. Nested inside the sub-component
174
-
Nest the modifier code inside the subcomponent using `.c-component.c--modifier &`.
169
+
#### 2. Styles grouped with sub-component
170
+
Nest the modifier code inside the sub-component using `.c-component.c--modifier &`.
175
171
176
-
This method works well when a root-level modifier affects multiple sub-components, or when you are working with complicated/intricate sub-components.
172
+
This method makes it easier to visualize the differences between a sub-component and its modified states.
177
173
178
174
```scss
179
175
.c-blog-post__title {
@@ -185,7 +181,7 @@ This method works well when a root-level modifier affects multiple sub-component
185
181
}
186
182
```
187
183
188
-
When using the above method in larger files, add a comment to the `.c-component` like so:
184
+
In larger files, adding a comment in the `.c--modifier` notes can be helpful:
189
185
```scss
190
186
// Blog Post
191
187
// ===
@@ -195,8 +191,7 @@ When using the above method in larger files, add a comment to the `.c-component`
0 commit comments