Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I react-bootstrap change the color of the tabs

I want to change the color of the tabs used in react-bootstrap. but when I change the style it goes for the content and not the tabs. How can I do it.

like image 701
Zeeshan Avatar asked Apr 09 '17 12:04

Zeeshan


People also ask

How do I change the active tab color in bootstrap?

You can always modify your navigation list through css. Use this css code instead, in that way use you use the a tag to change the color and its background-color. It's improper to use the li tag to set the background only and a tag to set the color of the text.

How do I change bootstrap color in React?

To customize Bootstrap, create a file called src/custom. scss (or similar) and import the Bootstrap source stylesheet. Add any overrides before the imported file(s). You can reference Bootstrap's documentation for the names of the available variables.

How do I style a bootstrap tab?

You can do this by adding styles to tab-pane. Let's add a style class to div with style class “tab-content” call “my-tab.” This new style class will override the default class properties. Now you can add the following line of code to CSS.

How do you style tabs in React JS?

You can customize the Tab style by overriding its header and active tab CSS classes. Define HTML string for adding animation and customizing the Tab header and pass it to text property. Now you can override the style using custom CSS classes added to the Tab elements.


2 Answers

Specify a class on the <Tabs className="myClass"> component. To modify the color of the tabs your CSS is going to look a little hacky but I haven't found a better way to do this:

.myClass ul > li > a {
    background-color: gray;
    color: white;
}

You will notice that this does not cover hover and inactive states so there is a little bit more work for you to do, but this should be enough to head you in the right direction.

Working example at CodePen

like image 152
Todd Chaffee Avatar answered Sep 23 '22 02:09

Todd Chaffee


In react-bootstrap v4 the Tab component has a property called tabClassName (https://react-bootstrap-v4.netlify.app/components/tabs/#tab-props). With its help you cann pass in a class and define CSS which will override the default classes:

# in css file:

.coloredTab {
  background-color: red;
}

# in jsx file:
<Tab ... tabClassName={classes.coloredTab} />

Didn't check the newest v5 though. Might even got better.

like image 33
Igor Gonak Avatar answered Sep 22 '22 02:09

Igor Gonak