Customize the background color of bootstrap's nav-pills

I am trying to customize a bootstrap navbar with individual elements as nav-pills. After recompiling bootstrap to change the default colors, I want to add a background color to the pills that is different from the hover and active states. How can I achieve this? Should I modify the app-wide CSS file for it, or is there a way to accomplish this using Bootstrap's less?

This section shows a snippet of my current navbar:

<nav class="navbar">
  <div class="container">

    <div class="collapse navbar-collapse elements">
      <ul class="nav nav-pills navbar-right">
        <li ng-class="setClass('/')"><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
        <li ng-class="setClass('/list')"><a href="/list">Browse</a></li>
        <li ng-class="setClass('/search')"><a href="/search">Search</a></li>
      </ul>
    </div>
  </div>
</nav>

https://i.sstatic.net/vkJFB.png

It is noticeable how the hovered element receives highlighting, the active one stands out, whereas the inactive ones blend into the background.

Answer №1

If you find that the default nav-pills in Bootstrap lack a background color, don't worry - you can easily set one yourself. Unfortunately, Bootstrap's default less configuration doesn't offer an option for this.

How about trying this simple solution:

.nav-pills > li > a {
    background: #f6f6f6;  /* choose your preferred color */
}


It's recommended to place this code in a separate CSS file rather than altering Bootstrap's core files. This way, when you update Bootstrap in the future, you can do so seamlessly with a configuration JSON file. But if you make direct changes to the CSS or less files, you'll need to remember and reapply those changes each time, risking them being overwritten during updates.
To keep your file organization tidy, consider creating a bootstrap_extended.css where you only include code that extends or modifies Bootstrap defaults not found on the customization page.


Alternatively, you could create a bootstrap_extended.less file and add

@import (inline) '../Content/bootstrap.less';

at the beginning. By using/compiling this file, you can generate a final, already extended CSS stylesheet for Bootstrap.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The impact of array splicing on data manipulation

I have a $scope array variable that I'm using to generate tabs on the front end, but I'm struggling with implementing a remove tab function. The code for removing tabs is as follows: function removeTab(index) { $scope.tabs.splice(index, 1); ...

Arrange the footer content into multiple columns

Hello! I'm currently working on creating a footer for my website. I've written this code and everything seems to be functioning correctly, except for the fact that the second row is positioned under the first row and taking up half of the bottom ...

Using the AngularJS double Array ng-repeat feature allows for easy iteration

I am in the process of developing a web application using AngularJS. My goal is to: Display both sets of arrays in one list using ng-repeat and eliminate any null values. For example, Value One A, Value One B, Value Two A, Value Two B Issues I am fa ...

Developing shapes using CSS and jQuery

I am struggling to create the exact contour as shown in the image. Despite trying, I have not been successful in achieving it. I used a lot of HTML child tags in my attempt, but I would prefer to keep it minimal. Is there a simpler way to accomplish this? ...

When viewed on mobile devices, the image shrinks significantly

I'm experiencing an issue where the image shrinks significantly when viewed on a mobile device or when zooming in the browser. Can you help me understand why this is happening and suggest a solution? Here are the HTML and CSS code snippets: HTML < ...

Utilizing JQuery to populate DIVs with JSON information

Hey! I recently received some helpful advice from a coding expert, and now I'm in the process of restructuring my code based on these recommendations: When using $.each(), you have the option to return true or false. If you return false, the loop wi ...

Adding margin causes Bootstrap 5 column to surpass 100vh height limit

I am experimenting with Bootstrap 5 on a simple webpage that contains one row with two columns. The left column is working correctly, but the right column is causing some issues. I want the webpage to be full-screen without any scrolling. However, whenever ...

Altering the DOM directly within the componentDidMount() lifecycle method without needing to use

In ReactJS, I am facing an issue while trying to manipulate the DOM in the componentDidMount() method. The problem lies in the fact that the DOM is not fully rendered at this point, requiring me to use a setTimeout function, which I find undesirable. Upon ...

Interactive carousel featuring thumbnail navigation and central highlighting of images

I've been struggling with this issue for the majority of the day, so any assistance would be greatly appreciated. My goal is to find a carousel that includes both next and previous navigation buttons attached to the main image. Additionally, I am loo ...

The issue with mobile responsiveness is specifically occurring on the Samsung Note 21 and iPhone 14 devices, while functioning properly on all other devices. Attempts to reproduce the error using Chrome dev tools

I'm facing a unique issue at the moment. The landing page I've created is highly responsive on all mobile devices except for the web owner's device: . Interestingly, it appears differently on the web owner's Samsung and iPhone devices:S ...

It seems that there is an issue with accessing the root directory while utilizing the yo

I'm currently working on setting up the Yeoman 1.0 beta's angular scaffolding and have been following these steps in my workflow: npm install generator-angular generator-testacular # installing generators yo angular # creati ...

What is the best way to space out words in a navigation bar?

Hello, I'm new to programming and have a question: How can I increase the spacing between words in this navigation bar? ul{ list-style-type: none; margin: 0px; padding: 0px; width: 100%; overflow: hidde ...

The button's color remains static in Internet Explorer despite attempts to change it using a linear gradient background image

I'm curious why the button appears grey in IE and turns blue on hover, rather than starting off blue and becoming darker blue when hovered over. I've managed to make it work in other browsers, but I'm struggling with the code for IE. Thank ...

Fadeshow not appearing on webpage (JavaScript/CSS/PHP)

I'm currently developing a PHP website and have incorporated JavaScript code for a 'fadeshow' (slideshow with fade effects). However, when I load the site, the fadeshow does not appear as expected. Previously, I had used a JavaScript 's ...

Adjusting the sidebarPanel height to match the mainPanel content in a shiny app

I'm currently developing an app that features a scrollable sidebarPanel alongside a mainPanel that can have varying heights, such as: library(shiny) ui <- fluidPage( headerPanel('Iris k-means clustering'), sidebarPanel(style = " ...

Creating identical class names for UL elements underneath LI using JavaScript

In my attempt to dynamically generate the class name within the ul element, I successfully achieved the expected result. The outcome can be viewed in the console of the snippet provided for reference. However, I'm facing a challenge when attempting t ...

Personalizing the dimensions of audio.js

I recently integrated the audio.js plugin into my website. I've added the necessary code to the header.php file located in the includes folder. <script src="audio/audiojs/audio.min.js"></script> While the player appears correctly on othe ...

Show material-ui cards in a row side by side

I attempted to showcase cards within a mapping loop while also utilizing the Grid in this manner. <div className={classes.root}> {data.tableData.childRows.map((el: any, idx: number) => { return ( &l ...

Is ng-repeat failing to bind values in the Dom?

When loading data dynamically to ng-repeat, I am encountering an issue where the data is not binding to ul. Typically, this can happen with duplicate indexes, but in my case I'm unsure of what's causing it. Any suggestions? main.html <div> ...

Generate a dynamic animation by combining two images using jQuery

My attempt to animate two images is not working. I received some help on Stack Overflow but still facing issues with my CSS and HTML code. This is the code I am using: $(document).ready(function() { $(".animar").click(function() { $("#img4" ...