local-link/skills/css-dev-skills/skills/css-refactor/SKILL.md
Upgrade legacy CSS to modern standards. Scans stylesheets for outdated patterns (floats, clearfix, vendor prefixes, old flexbox syntax, px media queries, @import, !important abuse) and replaces them with modern equivalents. Introduces cascade layers, extracts design tokens, and consolidates redundancy. Use when refactoring CSS, modernizing stylesheets, upgrading legacy code, removing vendor prefixes, or replacing floats with grid/flexbox.
npx skillsauth add lionad-morotar/simple-local-llm-server css-refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a CSS modernization specialist. Your job is to scan CSS files, identify legacy patterns, and replace them with modern equivalents. Always show before/after diffs so the user can review changes.
For the full modern pattern catalog, see the css-expert skill's modern-patterns.md. For the anti-pattern reference, see anti-patterns.md.
Copy this checklist and track progress:
Refactor Progress:
- [ ] Step 1: Scan — identify all CSS files in scope
- [ ] Step 2: Audit — catalog legacy patterns found
- [ ] Step 3: Prioritize — rank issues by impact
- [ ] Step 4: Refactor — apply modern replacements
- [ ] Step 5: Extract — pull design tokens into custom properties
- [ ] Step 6: Layer — introduce @layer architecture
- [ ] Step 7: Consolidate — remove redundancy
- [ ] Step 8: Review — present before/after diffs
Find all CSS files in scope. If the user hasn't specified files, search for **/*.css and list them with line counts. Flag the largest files first — they typically contain the most legacy code.
Scan every CSS file for the following categories. Report a summary table:
| Pattern | Count | Files | Severity |
|----------------------|-------|-----------------|----------|
| float layout | 3 | layout.css:12 | high |
| clearfix | 2 | layout.css:45 | high |
| !important | 14 | *.css | high |
| vendor prefixes | 8 | components.css | medium |
| px media queries | 5 | responsive.css | medium |
| @import | 2 | main.css:1-2 | medium |
| old flexbox syntax | 3 | nav.css | medium |
| hardcoded colors | 22 | *.css | low |
| px font sizes | 11 | typography.css | low |
| ID selectors | 4 | header.css | low |
High severity — fix first:
float: left/right used for layout (not text wrapping).clearfix or clear: both hacks!important (except on utility classes or third-party overrides)@import url(...) in CSS filesMedium severity:
-webkit-, -moz-, -ms-
-webkit-appearance and other still-needed prefixes@media (max-width: 768px) — px-based media queriesdisplay: -webkit-flex, display: -ms-flexbox, -webkit-boxbox-sizing applied per-element instead of with a resetLow severity:
px for font sizes instead of rem/clamp()#id selectors used for stylingmargin-left) instead of logical (margin-inline-start)Rank by impact:
!important, ID selectors (affect maintainability)@import, no layers (affect performance and scale)Apply these replacements. Always show before/after.
/* BEFORE */
.sidebar { float: left; width: 250px; }
.main { margin-left: 270px; }
.clearfix::after { content: ""; display: table; clear: both; }
/* AFTER */
.layout {
display: grid;
grid-template-columns: 250px 1fr;
gap: var(--space-m);
}
/* BEFORE */
.button { background: blue !important; }
.nav .button { background: green !important; }
/* AFTER */
@layer components {
.button { background: var(--_bg, var(--color-primary)); }
}
.nav .button { --_bg: var(--color-nav-action); }
/* BEFORE */
.flex { display: -webkit-flex; display: -ms-flexbox; display: flex; }
.transform { -webkit-transform: rotate(45deg); transform: rotate(45deg); }
/* AFTER */
.flex { display: flex; }
.transform { transform: rotate(45deg); }
/* BEFORE */
@media (max-width: 768px) { ... }
@media (min-width: 1024px) { ... }
/* AFTER */
@media (max-width: 48em) { ... }
@media (min-width: 64em) { ... }
Conversion: divide px by 16 → em.
/* BEFORE — in CSS */
@import url("reset.css");
@import url("components.css");
/* AFTER — in HTML */
/* <link rel="stylesheet" href="reset.css"> */
/* <link rel="stylesheet" href="components.css"> */
/* OR — if consolidating into one file, use @layer */
@layer reset { /* contents of reset.css */ }
/* BEFORE */
.box { display: -webkit-box; -webkit-box-orient: horizontal; -webkit-box-pack: center; }
/* AFTER */
.box { display: flex; justify-content: center; }
/* BEFORE */
:root { --primary: #3366ff; --danger: rgb(220, 53, 69); }
/* AFTER */
:root { --primary: oklch(55% 0.25 260); --danger: oklch(55% 0.22 25); }
/* BEFORE */
h1 { font-size: 32px; }
body { font-size: 16px; }
/* AFTER */
h1 { font-size: clamp(1.5rem, 1rem + 2vw, 3rem); }
body { font-size: clamp(1rem, 0.875rem + 0.5vw, 1.125rem); }
/* BEFORE */
.element { margin-left: 1rem; padding-right: 2rem; text-align: left; }
/* AFTER */
.element { margin-inline-start: 1rem; padding-inline-end: 2rem; text-align: start; }
Find repeated values and extract into custom properties using a three-layer architecture:
/* Layer 1: Primitive tokens (raw values) */
:root {
--blue-500: oklch(55% 0.25 250);
--gray-200: oklch(90% 0.01 250);
--radius-m: 0.5rem;
}
/* Layer 2: Semantic tokens (purpose-driven) */
:root {
--color-primary: var(--blue-500);
--color-border: var(--gray-200);
--radius-card: var(--radius-m);
}
/* Layer 3: Component tokens (scoped, underscore prefix) */
.card {
--_bg: var(--color-surface);
--_border: var(--color-border);
--_radius: var(--radius-card);
}
Look for:
Wrap existing styles in a layer architecture:
@layer reset, tokens, base, layout, components, utilities;
Map existing styles to appropriate layers based on their role. Un-layered styles beat all layers, so migrate everything into layers.
For every change, show a before/after diff:
File: layout.css
- .sidebar { float: left; width: 250px; }
- .main { margin-left: 270px; }
- .clearfix::after { content: ""; display: table; clear: both; }
+ .layout {
+ display: grid;
+ grid-template-columns: 250px 1fr;
+ gap: var(--space-m);
+ }
At the end, provide a summary:
Refactor Summary:
- Patterns fixed: 42
- Lines removed: 87
- Lines added: 61
- Net reduction: 26 lines
- Design tokens extracted: 15
- Cascade layers introduced: yes
- Files modified: 4
float for text wrapping around an image), leave it — only replace layout floats.tools
理解用户意图;listen 模式通过 grill-me 深挖任务并归档经验
development
给 VSCode(Insiders/Stable) 内置 ripgrep 加 5s 超时包装,防止搜索卡死吃满 CPU。--on 包装(幂等) / --off 还原 / 不带参数查状态。Use when VSCode 搜索卡死、rg 进程占满 CPU,或 VSCode 更新后超时保护失效需要重包。
development
为指定项目创建完全隔离的 hapi(Claude Code On the Go)实例,包括独立数据目录、LaunchAgent 持久化、zsh wrapper 和 app.hapi.run 直连 URL。与全局 ~/.hapi 互不干扰。
development
关闭承载当前 Claude Code 会话的宿主(VSCode 窗口或其终端面板),连同 claude 一起退出。通过 close-host-window 扩展触发:先 SIGTERM claude(走完 SessionEnd hooks)再关 host,不抢焦点、不丢 hooks。--host vscode 关窗口、--host terminal(默认)只关终端面板。Use when 任务结束要随宿主退出,或需精确关闭某 claude 终端所在窗口/面板。