CSS Fundamentals Skill
Master core CSS concepts: selectors, specificity, box model, positioning, and units.
Overview
This skill provides atomic, focused guidance on CSS fundamentals with type-safe parameters and comprehensive validation.
Skill Metadata
| Property |
Value |
| Category |
Core CSS |
| Complexity |
Beginner to Intermediate |
| Dependencies |
None |
| Bonded Agent |
01-css-fundamentals |
Usage
Skill("css-fundamentals")
Parameter Schema
parameters:
topic:
type: string
required: true
enum: [selectors, specificity, box-model, positioning, units, display]
description: The CSS fundamental topic to explore
level:
type: string
required: false
default: beginner
enum: [beginner, intermediate, advanced]
description: Depth of explanation
include_examples:
type: boolean
required: false
default: true
description: Include code examples
validation:
- rule: topic_required
message: "Topic parameter is required"
- rule: valid_enum
message: "Topic must be one of: selectors, specificity, box-model, positioning, units, display"
Topics Covered
Selectors
- Element, class, ID selectors
- Attribute selectors
[attr], [attr=value]
- Pseudo-classes
:hover, :focus, :nth-child()
- Pseudo-elements
::before, ::after
- Combinator selectors
>, +, ~
Specificity
- Specificity calculation (0,0,0,0)
- Cascade order rules
!important usage and pitfalls
- Inheritance patterns
Box Model
- Content, padding, border, margin
box-sizing: border-box vs content-box
- Margin collapse behavior
- Inline vs block dimensions
Positioning
static, relative, absolute, fixed, sticky
- Stacking context and z-index
- Containing block rules
- Offset properties (top, right, bottom, left)
Units
- Absolute: px, pt, cm
- Relative: em, rem, %, vh, vw
- Newer units: ch, lh, cqi, cqw
- When to use which unit
Retry Logic
retry_config:
max_attempts: 3
backoff_type: exponential
initial_delay_ms: 1000
max_delay_ms: 10000
retryable_errors:
- TIMEOUT
- RATE_LIMIT
- TEMPORARY_FAILURE
Logging & Observability
logging:
entry_point: skill_invoked
exit_point: skill_completed
log_parameters: true
log_response_size: true
metrics:
- invocation_count
- success_rate
- avg_response_time
Quick Reference
Specificity Calculator
Inline styles → 1,0,0,0
ID selectors → 0,1,0,0
Classes/attrs → 0,0,1,0
Elements → 0,0,0,1
Example: div#header .nav a:hover
0,1,2,2 (ID=1, class+pseudo=2, elements=2)
Box Model Visual
┌─────────────────────────────────┐
│ MARGIN │
│ ┌─────────────────────────┐ │
│ │ BORDER │ │
│ │ ┌─────────────────┐ │ │
│ │ │ PADDING │ │ │
│ │ │ ┌─────────┐ │ │ │
│ │ │ │ CONTENT │ │ │ │
│ │ │ └─────────┘ │ │ │
│ │ └─────────────────┘ │ │
│ └─────────────────────────┘ │
└─────────────────────────────────┘
Unit Recommendations
| Use Case |
Recommended Unit |
| Typography |
rem |
| Spacing |
rem or em |
| Borders |
px |
| Viewport layouts |
vh, vw, % |
| Container layouts |
% or fr |
Code Examples
Selector Efficiency
/* Efficient: Single class */
.nav-link { }
/* Less efficient: Descendant chain */
nav ul li a { }
/* Prefer attribute selectors */
[data-state="active"] { }
Box Model Reset
*, *::before, *::after {
box-sizing: border-box;
}
* {
margin: 0;
padding: 0;
}
Test Template
describe('CSS Fundamentals Skill', () => {
test('validates topic parameter', () => {
expect(() => skill({ topic: 'invalid' }))
.toThrow('Topic must be one of: selectors, specificity...');
});
test('returns selector examples for selectors topic', () => {
const result = skill({ topic: 'selectors', level: 'beginner' });
expect(result).toContain('.class');
expect(result).toContain('#id');
});
test('handles missing optional parameters', () => {
const result = skill({ topic: 'box-model' });
expect(result.level).toBe('beginner');
expect(result.include_examples).toBe(true);
});
});
Error Handling
| Error Code |
Cause |
Recovery |
| INVALID_TOPIC |
Unknown topic |
Show valid topics list |
| LEVEL_MISMATCH |
Level too advanced for topic |
Suggest appropriate level |
| PARAM_VALIDATION |
Invalid parameter type |
Return validation message |
Related Skills
- css-flexbox-grid (layout builds on fundamentals)
- css-architecture (naming builds on selectors)
- css-modern (extends selector knowledge)
1---2name: css-fundamentals3description: CSS fundamentals - selectors, specificity, box model, positioning, units4---5
6# CSS Fundamentals Skill
7
8Master core CSS concepts: selectors, specificity, box model, positioning, and units.
9
10## Overview
11
12This skill provides atomic, focused guidance on CSS fundamentals with type-safe parameters and comprehensive validation.
13
14## Skill Metadata
15
16| Property | Value |
17|----------|-------|
18| **Category** | Core CSS |
19| **Complexity** | Beginner to Intermediate |
20| **Dependencies** | None |
21| **Bonded Agent** | 01-css-fundamentals |
22
23## Usage
24
25```
26Skill("css-fundamentals")
27```
28
29## Parameter Schema
30
31```yaml
32parameters:
33 topic:
34 type: string
35 required: true
36 enum: [selectors, specificity, box-model, positioning, units, display]
37 description: The CSS fundamental topic to explore
38
39 level:
40 type: string
41 required: false
42 default: beginner
43 enum: [beginner, intermediate, advanced]
44 description: Depth of explanation
45
46 include_examples:
47 type: boolean
48 required: false
49 default: true
50 description: Include code examples
51
52validation:
53 - rule: topic_required
54 message: "Topic parameter is required"
55 - rule: valid_enum
56 message: "Topic must be one of: selectors, specificity, box-model, positioning, units, display"
57```
58
59## Topics Covered
60
61### Selectors
62- Element, class, ID selectors
63- Attribute selectors `[attr]`, `[attr=value]`
64- Pseudo-classes `:hover`, `:focus`, `:nth-child()`
65- Pseudo-elements `::before`, `::after`
66- Combinator selectors `>`, `+`, `~`
67
68### Specificity
69- Specificity calculation (0,0,0,0)
70- Cascade order rules
71- `!important` usage and pitfalls
72- Inheritance patterns
73
74### Box Model
75- Content, padding, border, margin
76- `box-sizing: border-box` vs `content-box`
77- Margin collapse behavior
78- Inline vs block dimensions
79
80### Positioning
81- `static`, `relative`, `absolute`, `fixed`, `sticky`
82- Stacking context and z-index
83- Containing block rules
84- Offset properties (top, right, bottom, left)
85
86### Units
87- Absolute: px, pt, cm
88- Relative: em, rem, %, vh, vw
89- Newer units: ch, lh, cqi, cqw
90- When to use which unit
91
92## Retry Logic
93
94```yaml
95retry_config:
96 max_attempts: 3
97 backoff_type: exponential
98 initial_delay_ms: 1000
99 max_delay_ms: 10000
100 retryable_errors:
101 - TIMEOUT
102 - RATE_LIMIT
103 - TEMPORARY_FAILURE
104```
105
106## Logging & Observability
107
108```yaml
109logging:
110 entry_point: skill_invoked
111 exit_point: skill_completed
112 log_parameters: true
113 log_response_size: true
114 metrics:
115 - invocation_count
116 - success_rate
117 - avg_response_time
118```
119
120## Quick Reference
121
122### Specificity Calculator
123
124```
125Inline styles → 1,0,0,0
126ID selectors → 0,1,0,0
127Classes/attrs → 0,0,1,0
128Elements → 0,0,0,1
129
130Example: div#header .nav a:hover
131 0,1,2,2 (ID=1, class+pseudo=2, elements=2)
132```
133
134### Box Model Visual
135
136```
137┌─────────────────────────────────┐
138│ MARGIN │
139│ ┌─────────────────────────┐ │
140│ │ BORDER │ │
141│ │ ┌─────────────────┐ │ │
142│ │ │ PADDING │ │ │
143│ │ │ ┌─────────┐ │ │ │
144│ │ │ │ CONTENT │ │ │ │
145│ │ │ └─────────┘ │ │ │
146│ │ └─────────────────┘ │ │
147│ └─────────────────────────┘ │
148└─────────────────────────────────┘
149```
150
151### Unit Recommendations
152
153| Use Case | Recommended Unit |
154|----------|------------------|
155| Typography | rem |
156| Spacing | rem or em |
157| Borders | px |
158| Viewport layouts | vh, vw, % |
159| Container layouts | % or fr |
160
161## Code Examples
162
163### Selector Efficiency
164
165```css
166/* Efficient: Single class */
167.nav-link { }
168
169/* Less efficient: Descendant chain */
170nav ul li a { }
171
172/* Prefer attribute selectors */
173[data-state="active"] { }
174```
175
176### Box Model Reset
177
178```css
179*, *::before, *::after {
180 box-sizing: border-box;
181}
182
183* {
184 margin: 0;
185 padding: 0;
186}
187```
188
189## Test Template
190
191```javascript
192describe('CSS Fundamentals Skill', () => {
193 test('validates topic parameter', () => {
194 expect(() => skill({ topic: 'invalid' }))
195 .toThrow('Topic must be one of: selectors, specificity...');
196 });
197
198 test('returns selector examples for selectors topic', () => {
199 const result = skill({ topic: 'selectors', level: 'beginner' });
200 expect(result).toContain('.class');
201 expect(result).toContain('#id');
202 });
203
204 test('handles missing optional parameters', () => {
205 const result = skill({ topic: 'box-model' });
206 expect(result.level).toBe('beginner');
207 expect(result.include_examples).toBe(true);
208 });
209});
210```
211
212## Error Handling
213
214| Error Code | Cause | Recovery |
215|------------|-------|----------|
216| INVALID_TOPIC | Unknown topic | Show valid topics list |
217| LEVEL_MISMATCH | Level too advanced for topic | Suggest appropriate level |
218| PARAM_VALIDATION | Invalid parameter type | Return validation message |
219
220## Related Skills
221
222- css-flexbox-grid (layout builds on fundamentals)
223- css-architecture (naming builds on selectors)
224- css-modern (extends selector knowledge)