Css

From clawic/skills · View interactive version

Css is an AI agent skill from the GitHub repository clawic/skills. Writes and debugs CSS: flexbox and grid layout, z-index and stacking, responsive breakpoints, theming, and render performance. Use when a layout breaks or overflows, z-index does nothing, the page scrolls sideways, `position: sticky` won''t stick, text won''t truncate, styles lose the cascade or nee

How to use this skill

Skill file

User preferences and memory live in ~/Clawic/data/css/ (see setup.md on first use, memory-template.md for the file format). If you have data at an old location (~/css/ or ~/clawic/css/), move it to ~/Clawic/data/css/, and say in one line that you moved it and from where.

Configuration

User-dependent variables. Defaults apply until the user states a preference; store them in ~/Clawic/data/css/config.yaml.

| Variable | Type | Default | Effect |

|---|---|---|---|

| authoring_mode | plain-css \| sass \| tailwind \| css-in-js | plain-css | Syntax of every emitted example, and which advice in architecture.md applies (layers and nesting vs utility ordering vs zero-runtime extraction) |

| browser_support | evergreen \| widely-available \| legacy | evergreen | Gates which features ship bare vs behind @supports: legacy also adds vendor-prefixed fallbacks and blocks the Chromium-first features flagged in compatibility.md |

| naming_convention | bem \| utility \| css-modules \| none | none | Class names in examples and the specificity ceiling enforced in reviews (architecture.md — Keeping It Clean) |

| rem_base | number px (10-16) | 16 | Every px→rem conversion, including the fluid-type derivation in responsive.md (rem term = px ÷ rem_base) |

| a11y_target | aa \| aaa | aa | Which row of Accessibility Floor gates output: AA = 4.5:1 body / 24×24 targets, AAA = 7:1 body / 44×44 targets |

| explanation_depth | mechanism \| fix-only | mechanism | How much of the why ships with each answer: mechanism names the cause (stacking context, flex sizing) before the declaration; fix-only emits the declaration plus one line |

| output_shape | diff \| full-sheet | diff | Emitted code: diff = only the changed declarations in context; full-sheet = the complete rewritten stylesheet or component block |

Preference areas to record as the user reveals them:

When To Use

Quick Reference

| Situation | Play |

|---|---|

| z-index ignored despite a huge value | Stacking Contexts below — find the context root; never just bump the number |

| Flex item overflows / text won't truncate | min-width: 0 on the flex child (default min-width is min-content) |

| The rule is written but nothing changes | debugging.md — symptom→cause chains, starting with "is it even matching?" |

| Breaks with real content, sticky dead, footer floats, margin leaks | layout.md |

| Component must adapt to its container; fluid type; mobile viewport bugs | responsive.md |

| Specificity fight, @layer, :has(), custom-property gotchas | selectors.md |

| Jank, layout shift, slow paint, font flash | performance.md |

| Transition never fires, enter/exit animation, view transitions, reduced motion | animations.md |

| Line-height inheritance, measure, variable fonts, hyphenation, tabular numbers | typography.md |

| oklch vs hsl, color-mix(), gradient banding, wide gamut | color.md |

| Dark mode, design tokens, multi-brand, theme flash on load | theming.md |

| Inputs, selects, checkboxes, validation states, autofill styling | forms.md |

| Modal behind the header, dropdown clipped, tooltip placement | overlays.md |

| Scroll snap, custom scrollbars, anchor link lands under the sticky header | scrolling.md |

| Data table: sticky header, responsive behavior, column sizing | tables.md |

| Shadows, filters, masks, clip-path, blend modes, 3D transforms | effects.md |

| Starting a stylesheet: what goes in the reset and base layers, in what order | reset.md |

| Sheet organization, layer strategy, nesting, Sass migration, shadow DOM | architecture.md |

| Works in Chrome, breaks in Safari or Firefox; HTML email | compatibility.md |

| Print or PDF output wrong | print.md |

| RTL mirroring, CJK line breaking, logical properties, text expansion | internationalization.md |

| Anything else CSS | Core Rules below, then debugging.md to name the mechanism |

Core Rules

  1. Diagnose before adding CSS: reproduce, isolate in DevTools, name the mechanism (stacking context, flex sizing algorithm, margin collapse). A property added without a named mechanism is the next bug.
  2. Animate only transform and opacity — the only common properties that skip layout and paint. Frame budget = 1000ms / 60fps ≈ 16.7ms for style, paint, and your JS combined; one layout-triggering animation spends it alone.
  3. One centering default: parent display: grid; place-content: center. Escape hatch: position: absolute; inset: 0; margin: auto when the child must overlay (needs a resolvable size, e.g. width: fit-content).
  4. Never bare viewport units for text. font-size: clamp(1rem, 0.77rem + 0.91vw, 1.5rem) — the rem term is what keeps browser zoom and user font-size working; pure-vw text fails WCAG 1.4.4 (resize to 200%). Derivation of the numbers: responsive.md.
  5. Size intrinsically first (min(), clamp(), fit-content, auto-fit grids), media queries second, container queries when one component lives at different widths.
  6. !important in component code is a debt marker. Order wars belong in @layer — unlayered author styles beat all layered ones regardless of specificity (selectors.md).
  7. Overlays belong in the top layer, not high in the z-index scale. <dialog>.showModal() and popover escape every stacking context and every overflow: hidden ancestor; a z-index arms race means the wrong mechanism is in use (overlays.md).
  8. A component styles its inside, never its outside: no margin, no width, no position on the component root — the parent layout owns placement. Components that set their own outer geometry break on the second reuse and get "fixed" with !important.

Stacking Contexts

The single most common CSS debugging failure: raising z-index on an element trapped inside a context.

Flexbox and Grid Mental Model

Modern CSS Worth Using

Compatibility floor: everything here is in all three engines unless marked; version-sensitive items are dated in compatibility.md.

Accessibility Floor

Canonical home for these numbers — other files point here.

Output Gates

Before shipping a stylesheet or component styles, verify:

Traps

| Trap | Why it fails | Do instead |

|---|---|---|

| Bumping z-index to 9999 | Element is inside a stacking context; only the context root competes outside | Walk-up procedure (→ Stacking Contexts) |

| Animating height/top/left/margin | Layout runs every frame and blows the 16.7ms budget (Core Rule 2) | transform; for height-to-auto, the grid-rows trick (→ layout.md) |

| overflow: hidden to kill a stray scrollbar | Hides the symptom and creates a scroll container: breaks sticky descendants, clips shadows and focus rings | Find the overflowing element first; when it cannot be removed, html { overflow-x: clip } — clip creates no scroll container, so sticky survives (→ layout.md) |

| var(--x, fallback) as a safety net | A declared-but-invalid value skips the fallback ("invalid at computed-value time") | @property with initial-value (→ selectors.md) |

| Global will-change or translateZ(0) "GPU hints" | Every layer holds GPU memory; hundreds of layers slow compositing | will-change only on elements actually animating, only while animating (→ performance.md) |

| 100vh full-screen sections | Mobile browser UI overlaps the bottom of the section | 100svh; dvh only when live resize is acceptable (→ responsive.md) |

| !important to win a specificity fight | Escalation is one-way; the next override needs another !important | @layer ordering (→ selectors.md) |

| :empty for empty states | Whitespace text nodes count as content in most engines | Control the markup, or a class set by the renderer |

| transition: all | Animates properties added later — including layout ones — and turns theme swaps into visible sweeps | Enumerate the properties you mean (→ animations.md) |

| :invalid for error styling | Matches an untouched empty required field on first paint: the form is red before typing | :user-invalid (→ forms.md) |

| line-height: 150% | Percentages inherit the COMPUTED value, so a big heading inherits the body's pixel leading | Unitless line-height: 1.5 (→ typography.md) |

| display: none for screen-reader-only text | Removes it from the accessibility tree — nobody hears it | The clip pattern (→ Accessibility Floor) |

| text-align: left and margin-left in a themeable product | The first RTL locale mirrors everything except your CSS | Logical properties (→ internationalization.md) |

Where Experts Disagree

Related Skills

More Clawic skills, get them at https://clawic.com/skills/css (install if the user confirms):

Feedback

Part of Clawic, the verified skill library. Get this skill: https://clawic.com/skills/css.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.