Design a CSS architecture for legacy migration with a scoped reset. Create a .new-app…
- User
Design a CSS architecture for legacy migration with a scoped reset. Create a .new-app class that resets all global styles from Bootstrap or Foundation inherited from the legacy parent page so new React components inside look consistent regardless of CSS pollution.
- Assistant
Designing scoped CSS reset for legacy migration
Propose wrapping the new app in a
.new-appcontainer that applies a scoped CSS reset overriding global styles without affecting outside. Use a manually curated reset inside.new-appthat sets box-sizing, removes margins/paddings, resets form elements, and defines base typography to provide a consistent baseline despite inherited Bootstrap/Foundation styles. Avoid heavyall: unsetresets due to display issues; instead combine minimal resets on.new-app *with explicit styles for common elements. A maintainable approach uses SCSS to namespace resets under.new-app, optionally integrating a scoped normalize.css. This creates isolation via CSS without shadow DOM, enabling new React components inside.new-appto render with clean, predictable styles. When you embed a modern component tree into a page that already has a framework like Bootstrap or Foundation on it you are fighting two things:- Element‑level rules (e.g.
body { font: … },h1 { margin: … }) that cascade into your tree. - Class rules on generic selectors (e.g.
button,.row,.col‑md‑6) that may match your markup.
The two strategies that actually isolate you are either a true shadow DOM host, or scoping a reset and your own base styles under a wrapper with higher specificity than the global element selectors.
A simple, repeatable architecture for the latter looks like this:
- Wrap the React root in a dedicated class:
<!-- legacy page --> <link rel="stylesheet" href="/legacy/bootstrap.css"> … <div class="new-app" id="react-root"></div> <script src="/bundle.js"></script>- Ship a “scoped reset” and base styles that only apply below
.new‑app. You can take a normalize/reset file and prefix it, or author your own. In Sass you can even import normalize and wrap it in a nesting scope.
// tokens for your new app $new-font-stack: system-ui, -apple-system, 'Segoe UI', sans-serif; $new-text-color: #1b1b1b; $new-bg-color: #fff; // base wrapper: create an isolated formatting context .new-app { isolation: isolate; // prevent z-index bleed font-family: $new-font-stack; font-size: 16px; line-height: 1.5; color: $new-text-color; background-color: $new-bg-color; } // scoped reset .new-app *, .new-app *::before, .new-app *::after { box-sizing: border-box; margin: 0; padding: 0; border: 0; font: inherit; color: inherit; background: none; text-decoration: none; } /* Restore sensible display defaults */ .new-app div, .new-app section, .new-app article, .new-app header, .new-app footer, .new-app nav, .new-app ul, .new-app ol, .new-app li, .new-app p, .new-app form { display: block; } .new-app ul, .new-app ol { list-style: none; } /* Form element resets */ .new-app button, .new-app input, .new-app select, .new-app textarea { font: inherit; color: inherit; background: transparent; border: none; outline: none; box-shadow: none; appearance: none; } /* Typographic defaults */ .new-app h1 { font-size: 2rem; font-weight: 700; margin: 0 0 .5em; } .new-app h2 { font-size: 1.5rem; font-weight: 600; margin: 0 0 .5em; } .new-app p { margin: 0 0 1em; } /* …add whatever base styles your design system needs… */If you can target modern browsers you can be even more aggressive and “wipe” the inherited styles using
all/revertand then rebuild:.new-app { all: revert; /* drop author styles from parent, keep UA defaults */ isolation: isolate; font-family: system-ui, sans-serif; line-height: 1.5; color: #111; } .new-app * { all: revert; box-sizing: border-box; font: inherit; color: inherit; }Because this is scoped under
.new‑appit won’t touch the legacy UI. Your component styles live in their own files (CSS Modules, CSS‑in‑JS, BEM, etc.) and will win over the reset because of normal cascade order.For larger projects, automate the prefixing: take
normalize.cssand wrap it in.new-app { … }using a preprocessor or a PostCSS plugin, so you don’t have to maintain a fork. This gives you a clean, predictable baseline for React components regardless of the polluted global CSS. - Element‑level rules (e.g.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.