Another approach…
First, you can quickly see what classes target a particular component by clicking on the component and looking at the Attributes panel. In the field Class Names, you will see the Bootstrap CSS class (or classes) that are applied to the component. If you look at the Styles panel, you will see the actual CSS rules that comprise these classes.
If you add a Navbar component to a new project, and click it, you will see three Class Names…
navbar navbar-expand-md bg-body
The class bg-body
contains the rule that sets the color of the Navbar background, which is…
.bg-body {
--bs-bg-opacity: 1;
background-color: rgba(var(--bs-body-bg-rgb),var(--bs-bg-opacity))!important;
}
If you want to change the background color of the Navbar through the visual interface (so you don’t have to write any CSS), select it, then go to the Appearance panel > Background > BG Color and change the color to what you want (for the purposes of this example, I will use solid red.) This will add inline CSS styling which you will see in the Styles panel thusly…
element.style {
background: rgb(255,0,0);
}
Now you will say, “but the background color of the Navbar did not change!” This is because in Bootstrap 5.3, the .bg-body
class with the background-color
rule uses the uses the !important
declaration. This overrides the inline style we just created. To force our new style to override the Bootstrap style, we simply manually edit the CSS we created and add the !important
declaration to the rule…
element.style {
background: rgb(255,0,0) !important;
}
Then, in the Style panel, click the three dots to the right of the rule, choose Extract Rules, pick the CSS stylesheet in which you want your rule to reside (ex. styles.css), and you’re done.
Now, as I learned CSS many years ago, the use of the !important
declaration was to be avoided as much as possible. The belief was that relying on !important
to style your website usually meant you weren’t writing your CSS correctly. But Bootstrap (for whatever reason) has embraced the use of the !important
declaration throughout their default CSS, which forces us to use it to override the default styling.