Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap individual navbar menu item colors [duplicate]

I have a navbar menu in Bootstrap like this:

<ul class="nav navbar-nav navbar-right">
   <li><a href="#">Menu Item 1</li>
   <li><a href="#">Menu Item 2</a></li>
   <li><a href="#">Menu Item 3</a></li>
   <li><a href="#">Change Color of this Menu Item</a></li>
</ul>

I would like to change the color of the final list item so it does not inherit the standard color/hover properties. Is it possible to target just the final menu item via CSS and override my Bootstraps CSS?

My CSS here:

.navbar-default .navbar-nav > li > a {
   color: #ffffff;
   font-family: "Fjalla One", sans-serif;
   text-transform: uppercase;
   font-size: 17px;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
   color: #0091c1;
   background-color: transparent;
}
like image 908
lowercase Avatar asked Dec 04 '25 10:12

lowercase


2 Answers

use last-child

.navbar-nav li:last-child {
    background: red;
}

see this js-fiddle.

http://jsfiddle.net/DTcHh/2690/

like image 121
Jørgen Avatar answered Dec 07 '25 17:12

Jørgen


Yes, you can do this with the :last-child pseudo selector, like this:

.navbar-nav > li > a {
    color: blue;
}
.navbar-nav > li:last-child > a {
    color: green;  
}
<ul class="nav navbar-nav navbar-right">
  <li><a href="#">Menu Item 1</li>
  <li><a href="#">Menu Item 2</a></li>
  <li><a href="#">Menu Item 3</a></li>
  <li><a href="#">Change Color of this Menu Item</a></li>
 </ul>
like image 22
Casey Rule Avatar answered Dec 07 '25 16:12

Casey Rule