Customizing Bootstrap, Sort of
Love it or hate it, Bootstrap is a mainstream CSS framework
that is very popular and comes packaged with Blazor Templates. I have gone on record that I prefer Tailwinds
CSS https://codingwithdavid.blogspot.com/2022/08/jumped-feet-first-with-blazor-and.html
over Bootstrap, but Bootstrap is so in use that you need to know it and use it
at times.
I did post about how to update to Bootstrap 5.3 and how to add a Bootstrap dark mode switcher to your applications.
One of the biggest complaints about Bootstrap is that
all the web applications look the same. There
is some truth to that, but you can add themes, or use SAAS and fully customize Bootstrap. But these solutions come with their own
issues, like upgrading to new releases of Bootstrap.
In addition, if you are building a suite of applications,
say for a line of business, you have to ensure the same style and user
experience is used in all the applications.
This just compounds the issues of a fully customized Bootstrap solution.
Solution
I have found a more workable solution that should be more flexible
and more maintainable. Once you think
about it, this solution does make a lot of sense. You just need to take advantage of the Cascading
part of CSS. You create a “branding CSS”
that overrides the parts of the Bootstrap framework that you want to change.
By adding your own brand CSS file you can make your application look any way you want while using Bootstrap like you have been.
Adding your brand CSS style sheet in App.razor
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="myBrand.css" />
<link rel="stylesheet" href="app.css"
/>
This works well for elements and classes.
h1 {
font-size: 10rem
}
.btn-primary {
color: white;
background-color: #f066d9;
border-block-color: #000;
}
Use Between Projects
Default Bootstrap
With myBrand.CSS
Summary
While this is a simple solution, it works for me. I like finding these tips, it makes me much
more efficient at building applications.
Comments
Post a Comment