Consider using CSS isolation
How to add a different CSS to a razor page in Blazor WASM?
I am working on a Blazor WASM e-commerce application using the .NET 6 old version with a default template. I want to add a new razor page with a different look while keeping the old ones in the project. How can I achieve this? Specifically, I want to add a new page with custom CSS and JavaScript, without affecting the existing pages. Can you guide me on how to do this step by step? Thank you.
2 answers
Sort by: Most helpful
-
-
Bruce (SqlWork.com) 64,816 Reputation points
2024-06-05T00:39:45.18+00:00 you need to be careful. a Blazor app (server or WASM) is a spa. pages are not really pages, they are dynamic html. this means every referenced css and javascript file stays loaded. if you load two different css framework, they may have conflicting styles. javascript frameworks may also have conflicting functions, or worse conflicting dependencies.
CSS isolation and inline style can help, but don't handle framework conflicts. if you write the javascript, be sure to use a namespace for the new page(s).