css
CSS conventions, layout systems, and modern patterns: predictable styles through low specificity and explicit cascade control. Invoke whenever task involves any interaction with CSS code — writing, reviewing, refactoring, debugging, or understanding stylesheets, SCSS, layout, or responsive design.
xobotyi · Static checks on file
Installation
Read the source and dependencies before running a command. Copying does not install or execute anything.
npx skills add xobotyi/cc-foundry --skill cssAbout this skill
name: css description: >- CSS conventions, layout systems, and modern patterns: predictable styles through low specificity and explicit cascade control. Invoke whenever task involves any interaction with CSS code — writing, reviewing, refactoring, debugging, or understanding stylesheets, SCSS, layout, or responsive design.
CSS
Predictability is the highest CSS virtue. If your styles require !important to work, restructure the cascade.
CSS rewards explicit, low-specificity selectors and intentional cascade ordering. Prefer boring, readable patterns over clever one-liners.
References
- Layout — [
${CLAUDE_SKILL_DIR}/references/layout.md]: Flex shorthand values, grid details (subgrid, implicit rows, alignment), layout patterns - Modern CSS — [
${CLAUDE_SKILL_DIR}/references/modern-css.md]: Extended modern CSS patterns and examples - SCSS — [
${CLAUDE_SKILL_DIR}/references/scss.md]:@forwardpatterns, module configuration, built-in modules, file organization - Responsive — [
${CLAUDE_SKILL_DIR}/references/responsive.md]: Extended responsive design patterns and examples - Methodologies — [
${CLAUDE_SKILL_DIR}/references/methodologies.md]: Methodology patterns and architecture details
Selectors and Specificity
- Single class selectors by default — keep specificity flat at 0-1-0
- Never use ID selectors for styling — IDs are for anchors and JS hooks
- Never qualify classes with elements —
.errornotdiv.error - Max nesting depth: 3 levels — deeper nesting couples CSS to DOM structure
- Avoid
!important— use cascade layers or restructure selectors instead; only valid use is in a low-priority reset layer for truly essential styles - Use
:where()to zero-out specificity when needed —:where(.card) .titlehas 0-0-1 specificity - Use
:is()with awareness — it takes the highest specificity of its arguments - Flatten nested selectors in SCSS — ability to nest does not mean you should
Layout Systems
Choosing Flexbox vs Grid
| Use Case | System |
|---|---|
| One-dimensional flow (row or column) | Flexbox |
| Two-dimensional layout (rows AND columns) | Grid |
| Content-driven sizing | Flexbox |
| Layout-driven sizing | Grid |
| Component internals (nav items, card content) | Flexbox |
| Page-level structure, complex arrangements | Grid |
| Items need to wrap naturally | Flexbox |
| Precise placement on named lines/areas | Grid |
Both work together — a grid item can be a flex container and vice versa.
Flexbox
- Always use the
flexshorthand — it sets intelligent defaults. See${CLAUDE_SKILL_DIR}/references/layout.mdfor the full shorthand value table flex-flow: row wrapcombinesflex-directionandflex-wrap- Use
flex-wrapwith aflexbasis for responsive layouts without media queries:flex: 1 1 300pxwraps items when they can't maintain 300px minimum - Centering:
display: flex; align-items: center; justify-content: centerormargin: autoon a flex child gapover margin hacks — works in both flexbox and grid- Avoid
justify-content: space-betweenwith wrap — causes orphan gaps; prefergap+flex-wrap
CSS Grid
repeat(auto-fit, minmax(250px, 1fr))is the canonical responsive grid — no media queries needed- Prefer
auto-fitoverauto-fill—auto-fitexpands columns to fill space;auto-fillkeeps empty tracks - Use named grid areas for page-level layouts — they auto-create named lines
- Never hardcode
pxwidths on grid items — usefr,minmax(), orauto grid-auto-flow: densefills visual holes — use carefully, it breaks visual/source order alignment (a11y concern)- Never use
orderin ways that break logical reading order - See
${CLAUDE_SKILL_DIR}/references/layout.mdfor subgrid, implicit rows, alignment shorthands, and negative line numbers
General Layout Rules
- Never use
floatfor layout — floats are for wrapping text around images - Intrinsic sizing first — use
flex-wrap,min(),max(),clamp()before reaching for media queries
CSS Nesting
- Use
&for pseudo-classes/elements and compound selectors —&:hover,&::before,&.active - Omit
&for descendant selectors —.card { .title {} }works &is required when the nested selector starts with a type selector —& p {}notp {}- Nesting at-rules (
@media,@supports,@container) nest directly inside rules - Specificity:
:is()wrapping applies in nesting — be aware that specificity may differ from the equivalent unnested selector - Max depth: 3 levels — same rule as flat CSS
Cascade Layers (@layer)
- Declare all layers at the top of the stylesheet in a single statement:
@layer reset, defaults, themes, components, utilities; - First declared = lowest priority; un-layered styles always beat layered styles
!importantreverses layer order —!importantin the lowest layer wins over!importantin higher layers- Import third-party CSS into sub-layers:
@import url('vendor.css') layer(vendor.bootstrap); - Use
revert-layerto roll back to the previous layer's value !importantin low layers is intentional — it means "this style is essential, don't override"- Don't create layers per-component — layers manage cascade priority between categories (reset vs component vs utility), not scope
- Nested layers:
@layer components { @layer buttons, cards; }— access via@layer components.buttons - Anonymous layers (
@layer { }) can't be appended to later
Container Queries
- Define containment:
container-type: inline-sizeon the wrapper - Name containers for targeting:
container: card / inline-size - Query by name:
@container card (width > 400px) { } - Unnamed queries hit the nearest ancestor container
Container Query Units
cqw