It is advisable that do not modify the file that you downloaded from the official page. There comes a time when you do not know what your styles are and what are the originals of Bootstrap and that creates maintenance problems (especially if another programmer tries to continue with the project and assumes that the styles are the originals).
What you must do is create your own CSS file in which the Bootstrap rules you want to change are "overwritten". This will keep the functionality of Bootstrap but with your modifications.
To have your styles take precedence over the default styles of Bootstrap, you have several options:
Write more specific selectors . Specificity is the method that browsers use to decide which styles will be applied when there is more than one selector defined for an element. They follow a formula that calculates the value of each rule giving more points (priority) in this order:
- ID.
- Classes and pseudo-classes.
- Type selectors and pseudo-elements.
So if you want a <nav>
to have your styles instead of those of Bootstrap, you can put an attribute id
and (re) define the styles only for that id.
Use !important
. When a style is defined and !important
is added at the end, that tells the browser that that style takes precedence over any other (it's more important). For example, although the style for div
is less specific than div#azul
, the red color will be applied because that property comes with !important
:
<style>
div {
color: red !important;
}
div#azul {
color: blue;
}
</style>
<div id="azul">Este texto es rojo</div>
But eye the use of !important
should be avoided because it is considered bad practice as you can read in this MDN article . If you use !important
everywhere, there comes a time when it loses its meaning and all it does is enlarge your CSS files and make them more difficult to read and maintain.
So personally, I would opt for the first method because it's cleaner .
In both cases, I would also recommend the CSS file where your styles are included in the project after where the Bootstrap styles are included (so, if two selectors have the same specificity value, your styles will prevail).