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.
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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With