Different tab designs with a variety of color schemes

I am looking to implement various color combinations for different tab selections using the background-color property.

For instance:

  • About: red .nav-tabs, dark red for .active,
  • Services: yellow .nav-tabs, dark yellow for .active,
  • ....
  • ....

and so forth.

What would be the most effective way to achieve this? I have come up with a plan:

  1. Pre-define styles for background colors,
  2. Retrieve the hash on the 'shown.bs.tab' event,
  3. Pass it into a switch statement,
  4. Apply css to .nav-tabs and .active.

Is there a better, more practical solution?

EDIT:

To clarify further, when I select the 'about' tab, the entire tab panel and other pills will turn red, with the active 'about' pill being dark red. If 'services' is selected, the tab panel and all pills will be yellow, with the active 'services' pill in dark yellow.

Answer №1

Hopefully, this solution will be beneficial for you. Feel free to insert more li items and assign appropriate classes based on your preferred colors.

$(function() {
  $('li:first').hover(function() {
    $(this).toggleClass('darkgreen');
    $('ul').find('li').not(this).toggleClass('green');
  })
  $('li:nth-of-type(2)').hover(function() {
    $(this).toggleClass('darkred');
    $('ul').find('li').not(this).toggleClass('red');
  })
})
ul li {
  list-style-type: none;
  width: 100px;
  padding: 20px;
  background-color: #444;
  color: #fff;
  text-transform: uppercase;
  transition:0.3s;
  cursor:pointer;
}

.green {
  background: lightgreen;
}

.darkgreen {
  background: darkgreen;
}

.darkred {
  background: darkred;
}

.red {
  background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
  <li>about</li>
  <li>services</li>


</ul>

Answer №2

If you are in search of the

siblings()

method within jQuery, refer to https://api.jquery.com/siblings/

When assigning tabs classes that correspond to specific colors, consider utilizing this line as a model:

$(".active").css("color", "blue").siblings().css("color", "darkerblue");

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

Unable to see the tokens on the connect four board when using Javascript and HTML

I'm currently developing a game of connect four using javascript, html, and css. I'm encountering an issue with the refreshGrid() function in game.js. At the moment, when I run my html file, I only see an empty board. The function is meant to ena ...

The jQuery gallery is experiencing some functionality issues

Having an issue with the gallery on my website (currently on my computer, not yet uploaded to a server). Here is the script for the gallery (loaded from the server using PHP): $(document).ready(function() { $('.gallery').hide(); $(' ...

Icons will be displayed when hovered over

Is it possible to display icons on hover in a div and hide them otherwise using just CSS? Or do I need to use javascript for this function? Thanks in advance! Example: HTML: <div id="text_entry"> <p>Some text here</p> <span ...

Can the placement and dimensions of the audio controls be customized?

I am working on an audio tag that initially hides the controls, and only shows them when a user clicks on a specific link. Here is the code snippet: var audio = document.getElementById(audioId); if (audio.paused) { audio.src = clip; audio.play(); ...

Tips for dividing the WordPress header navigation horizontally using separate PHP files

I am trying to customize my WordPress menu navigation by splitting it into two sections: left and right. I have added the menu function in the "functions.php" file to create the menu from the backend, and the frontend modifications will be done in the "hea ...

What sets apart Firefox and Chrome when it comes to interpreting the widths of flex items?

Looking to create a column layout using flexbox with three divs that span the full width of their parent container while maintaining a single line height. If the content in the center div overflows, I want it to display an ellipsis at the end. Check out t ...

The behavior of the input in React-bootstrap-daterangepicker is acting strangely

I'm encountering an issue while trying to integrate react-bootstrap-datepicker with input fields. The problem arises when I click on one of the inputs or press a key, causing the calendar to toggle (showing if hidden and vice versa). To reproduce this ...

JS animation triumphant

I have developed an app that utilizes a checkbox to control the appearance of an overlay on a screen. To ensure smooth transitions, I have incorporated animations into the process. #overlay{ position:absolute; height: 100vh; width: 100vw; ...

Employing featherlightGallery.js without the need for anchor tags

I've been experimenting with the FeatherlightGallery plugin for a lightboxing feature on an image slider. The slider contains images directly, without anchor tags wrapping them. However, I'm facing an issue where clicking next/prev doesn't l ...

At times, the CSS fails to load at first and does not refresh correctly when using F5 or CTRL F5, yet it occasionally loads when clicking on links

After dedicating a full day to trying to solve this issue, I am reaching out for some assistance. As a newcomer here, I apologize if this question has been asked before (I did search extensively and found nothing). The website I'm constructing for my ...

Enable search functionality for jQuery Select2 values that have been formatted by a formatter function

Trying to use a formatter with select2 for better alignment of code and description elements, but the plugin seems to be searching based only on the description rather than the entire text. This may be because it's only looking at the original <opt ...

Handling a jQuery Ajax success callback when it fails

I am encountering an issue with my ajax post request where even though I have separate success, failure, and status code handlers, when the request fails with a 400 error, part of the success function is still being executed. Can someone provide insight in ...

Ensure that an HTML table row remains fixed on the screen at all times

I'm looking to make a specific row in my HTML table always visible on the screen, either at the bottom if scrolled off or top. The row should scroll normally as part of the table when it's visible on the screen. How can I accomplish this using bo ...

Center alignment within input-group-prepend using Bootstrap 4

Is there a way to create a fixed width input-group-prepend that is larger than its content, while still keeping the content centered horizontally? I've experimented with text-center and align-items-center, but the content always ends up left aligned. ...

jQuery concealing selections from dropdown menus

Is there a way to use jquery sort to order dropdown list options and hide the "select" item in the dropdown? Check out my fiddle code here <select id="mySelect"> <option value="">select</option> <option value="1">a</opt ...

Can Antd's Typography.Paragraph be used as a multi-row Menu title?

I am having trouble getting multiple rows to work inside the Antd Submenu. When I select only one row, it works fine. However, when I try to select multiple rows, the ellipsis is not shown at all and the text remains in one row. <SubMenu ...

The listbox is experiencing display issues when viewed in the Chrome browser

Hey, I'm having an issue with adding background color and border to my Listbox. There seems to be a white strip on the right and bottom of the options. The layout rearranges properly when hovering over each item. <select> <option>H ...

Incorporate CSS and JavaScript files into every page of NetSuite

Is there a way to globally apply a CSS file or JavaScript code to all NetSuite pages in order to change the page direction to RTL? I attempted adding it through: SuiteScript >> Client >> Deployment : All Records, While I was able to successfu ...

Looking for assistance in personalizing a Tab slider plugin with jQuery and CSS?

Hi there! I stumbled upon this post (http://stackoverflow.com/questions/7645702/tab-slide-out-using-jquery-need-more-than-one) while experimenting with a plugin. I'm curious if anyone here knows how to integrate this plugin into a menu. My idea is to ...

Dealing with a JSON array in PHP that has been transferred through jQuery

Currently, I am facing a challenge with consuming a JSON array in PHP that is sent via JQuery. The data structure being transmitted to the server is as follows: [{"id":"7","start":"00:00","end":"02:30","date":"2013-11-15"},{"id":"10","start":"23:00","end" ...