In my design, I want to change my link and hover color in a specific part. I try my best but I can't do that. I am new in bootstrap. How can I change it for Bootstrap 4? A simple code is here-
<div class="card" style="max-width: 320px;">
<div class="card-header text-center"><h3>Navigation</h3></div>
<div class="card-block">
<ul class="nav navbar-nav" style="font-size: 1.50em;">
<li><a href="#" class="nav-link">Home</a></li>
<li><a href="#" class="nav-link">Documents</a></li>
<li><a href="#" class="nav-link">Videos</a></li>
<li><a href="#" class="nav-link">Gallery</a></li>
<li><a href="#" class="nav-link">Download</a></li>
</ul>
</div>
</div>
Two ways (which is actually one):
1. Adding your own styles
Actually bootstrap allows being overwritten in almost every case, therefore if you set something in your own .css it will overrule the style set in bootstrap.css
So adding this to your own .css:
You will see it works as a charm.
2. You can go and find everything set in bootstrap.css
I highly discourage you doing so unless it is really necessary, since every styling can be overwritten and it will create a cleaner structure for your styling.
Add this to your CSS:
Don't include the important tags at first though, see if there are any conflicts before adding them in. I personally prefer to just do a search & find of the relevant classes and parent divs to clear any conflicts or change the class name I'm using.
I'm just a noob, but Bootstrap 4 has a class called "nav-link" that you use in the link element tag. I was using a dark, primary colored navbar and the links were the same color. This solved it for me.
The CSS code of Bootstrap 4 is compiled with Sass (SCSS) instead of Less now. Bootstrap 4 ships with a grunt build chain. The "best" way to customize Bootstrap is using the default build chain.
bootstrap
(bootstrap-4-dev
) foldernpm install
in your consolegrunt dist
to recompile your CSS codeTo change the colors to can edit both
scss/bootstrap.scss
orscss/_variables.scss
now. The examples below editscss/bootstrap.scss
, make sure you redeclare the variables at the begin of thescss/bootstrap.scss
file.The color of the
.nav-link
andnav-link:hover
is set by the default colors for thea
selectors, you can changes these colors inscss/bootstrap.scss
as follows:Notice that the above change the colors of all your links. To change the colors of only
.nav .nav-link
or even.card .nav .nav-link
you will have to compile CSS code with a higher specificity. Do not use !importantAlso notice that Bootstrap currently is in a alpha state, so you should not use it for production. Variables to declare the colors of the
.nav-link
do not exist yet, but possible do in future, see also: https://github.com/twbs/bootstrap/issues/18630To change the color of the colors of all
.nav .nav-link
s in your code use the follow SCSS code at the end of yourscss/bootstrap.scss
file:To modify the colors of only the
.nav-links
inside the.cards
you should create CSS code with a higher specificity as follows:Of course you can also create your own CSS code at the end of the compiled
bootstrap.css
file. Depending of your needs use higher specificity;Change all links:
HTML:
Or with higher specificity:
Or even:
You are describing 3 things that can be tackled all at once within BS4 with sass. If you have access to the .scss file of your custom project and able to compile it, then I would recommend the following approach...
For this particular case, you can create a custom mixin like so:
I am assuming your have hex colors assigned to sass variables already like this:
If so, call your mixin from any specific location in your sass file. Sense this is your first time, notice how the following parameter
$m-color-white
represents the value for$bgcolorOff
parameter above. So pay close attention to where you put your colors to help define your custom variant.Finally, when you create your buttons, or anchor links, you can add the following to your element structures:
4 easy steps. After you do this the first time, every other time is easy. By taking this approach, you take full control of your link and hover colors. Re-use and/or create as many variants as you like.
Hope this helps
I found this link to be useful for my needs.
Bootstrap 4 Colors