How to change link color (Bootstrap)
I'm fully aware that the code in the original quesiton displays a situation of being navbar related. But as you also dive into other compontents, it maybe helpful to know that the class options for text styling may not work.
But you can still create your own helper classes to keep the "Bootstrap flow" going in your HTML. Here is one idea to help style links that are in panel-title regions.
The following code by itself will not style a warning color on your anchor link...
<div class="panel panel-default my-panel-styles">
...
<h4 class="panel-title">
<a class="accordion-toggle btn-block text-warning" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
My Panel title that is also a link
</a>
</h4>
...
</div>
But you could extend the Bootstrap styling package by adding your own class with appropriate colors like this...
.my-panel-styles .text-muted {color:#777;}
.my-panel-styles .text-primary {color:#337ab7;}
.my-panel-styles .text-success {color:#d44950;}
.my-panel-styles .text-info {color:#31708f;}
.my-panel-styles .text-warning {color:#8a6d3b;}
.my-panel-styles .text-danger {color:#a94442;}
...Now you can continue building out your panel anchor links with the Bootstrap colors you want.
For a direct change, you can use Bootstrap classes in the <a>
tag (it won't work in the <div>
):
<h4 class="text-center"><a class="text-warning" href="#">Your text</a></h4>
ul.nav li a, ul.nav li a:visited {
color: #anycolor !important;
}
ul.nav li a:hover, ul.nav li a:active {
color: #anycolor !important;
}
ul.nav li.active a {
color: #anycolor !important;
}
Change the styles as you wish.
If you are using Bootstrap 4, you can simple use a color utility class (e.g. text-success
, text-danger
, etc... ).
You can also create your own classes (e.g. text-my-own-color
)
Both options are shown in the example below, run the code snippet to see a live demo.
.text-my-own-color {
color: #663300 !important; // Define your own color in your CSS
}
.text-my-own-color:hover, .text-my-own-color:active {
color: #664D33 !important; // Define your own color's darkening/lightening in your CSS
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar-collapse">
<ul class="nav pull-right">
<!-- Bootstrap's color utility class -->
<li class="active"><a class="text-success" href="#">О нас</a></li>
<!-- Bootstrap's color utility class -->
<li><a class="text-danger" href="#">Как это работает</a></li>
<!-- Bootstrap's color utility class -->
<li><a class="text-warning" href="#">Цены</a></li>
<!-- Custom color utility class -->
<li><a class="text-my-own-color" href="#">Контакты</a></li>
</ul>
</div>