---
name: css-flexbox-layout-refactoring-tool
description: "Converts legacy float, inline-block, or table-cell layout CSS into Flexbox while preserving the rendered result, with the refactored stylesheet and a note on every change and what to check visually. Use when old float, inline-block, or table-cell layout CSS should be migrated to Flexbox without altering the page's appearance. Do not use for writing a new layout from a description, debugging a layout that already uses Flexbox, or moving to CSS Grid. Related topics: coding, css."
---

# CSS Flexbox Layout Refactoring Tool

Converts legacy float, inline-block, or table-cell layout CSS into Flexbox while preserving the rendered result, with the refactored stylesheet and a note on every change and what to check visually.

## When to use

Use this skill when old float, inline-block, or table-cell layout CSS should be migrated to Flexbox without altering the page's appearance. Do not use it for writing a new layout from a description, debugging a layout that already uses Flexbox, or moving to CSS Grid.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Describe what the original CSS renders: which elements align, stretch, clear, and which margins are fake gutters.
3. Map each legacy technique to its Flexbox equivalent and apply it on the chosen target elements with selectors unchanged.
4. Delete declarations that no longer have any effect on flex items and record each removal.
5. Add vendor prefixes only when requested and only for the oldest named browser.
6. Write the change list with old rule, new rule, and the visual difference to verify in a browser.

## Inputs

- **Original CSS** (longer free text)
- **Target elements** (choose any: .header, .nav, .footer, .sidebar, .content, .card-list, .form-row)
- **Desired layout direction** (choose one: row, column, row-reverse, column-reverse)
- **Gap size (px)** (number from 0 to 64)
- **Include vendor prefixes** (choose one: Yes, No)
- **Oldest browser to support** (free text, e.g. "Safari 14 or IE11 or evergreen only")

## Output

A fenced code block with the complete refactored CSS, then a bullet list of major changes, each with the old rule, the new rule, and what to check visually.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### CSS Flexbox Layout Refactoring Tool

Refactor this legacy layout CSS to Flexbox without changing what the user sees.

- Original CSS: {{Original CSS}}
- Target elements: {{Target elements}}
- Desired layout direction: {{Desired layout direction}}
- Gap size (px): {{Gap size (px)}}
- Include vendor prefixes: {{Include vendor prefixes}}
- Oldest browser to support: {{Oldest browser to support}}

Before changing anything, work out what the current CSS achieves: which elements sit side by side, which stretch, what clears, and which margins exist only to fake a gutter. Replace floats, inline-block with font-size hacks, table-cell displays, and clearfix helpers with a flex container on the chosen target elements, mapping each old trick to its flex equivalent (float: left to a row container, margin-right gutters to gap, vertical-align hacks to align-items, width percentages to flex-basis). Keep selectors and class names unchanged so markup does not need to move. Remove declarations that have no effect on a flex item (float, clear, vertical-align, display: inline-block) and say so. Add prefixes only when requested and only for the oldest browser named; evergreen browsers need none. Output the complete refactored CSS in a fenced block, then a list of each major change with the old rule, the new rule, and any visual difference to check in the browser.

## Pitfalls

- Renaming classes during the refactor, which forces markup changes and turns a CSS-only task into a template rewrite.
- Leaving float and clear on the new flex items; they are ignored but mislead the next reader into thinking they matter.
- Replacing a margin gutter with gap but forgetting the old margin on the last child, which doubles the final spacing.
