Unable to modify the background color of the <SideNav> element

I've been working with react and recently discovered a side navbar design that caught my eye. However, I'm struggling to change the default background color from red. I've attempted creating custom CSS styles and adding className: bg-dark in various lines of code without success. Can anyone provide guidance on how to achieve this? Also, here is the link to the source where I found the side navbar:

import React, { Component } from "react";
import { Link } from "react-router-dom";
import { Navbar } from "react-bootstrap";
import SideNav, { Toggle, Nav, NavItem, NavIcon, NavText } from '@trendmicro/react-sidenav';
import '@trendmicro/react-sidenav/dist/react-sidenav.css';
import Routes from "./Routes";

class App extends Component {
  render() {
    return (
      <div className="App container">
      <SideNav
        onSelect={(selected) => {
            // Add your code here
        }}
      >
        <SideNav.Toggle />
        <SideNav.Nav defaultSelected="home">
            <NavItem eventKey="home">
                <NavIcon>
                    <i className="fa fa-fw fa-home" style={{ fontSize: '1.75em' }} />
                </NavIcon>
                <NavText>
                    <Link to="/">Scratch</Link>
                </NavText>
            </NavItem>
            <NavItem eventKey="sites">
                <NavIcon>
                    <i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
                </NavIcon>
                <NavText>
                    <Link to="/sites">Sites</Link>
                </NavText>
            </NavItem>
            <NavItem eventKey="tours">
                <NavIcon>
                    <i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
                </NavIcon>
                <NavText>
                    <Link to="/tours">Tours</Link>
                </NavText>
            </NavItem>
            <NavItem eventKey="media">
                <NavIcon>
                    <i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
                </NavIcon>
                <NavText>
                    <Link to="/media">Media</Link>
                </NavText>
            </NavItem>
            <NavItem eventKey="newSite">
                <NavIcon>
                    <i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
                </NavIcon>
                <NavText>
                    <Link to="/newSite">Add new Site</Link>
                </NavText>
            </NavItem>
            <NavItem eventKey="profile">
                <NavIcon>
                    <i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
                </NavIcon>
                <NavText>
                    <Link to="/profile">Profile</Link>
                </NavText>
            </NavItem>

        </SideNav.Nav>
      </SideNav>
      <Routes />
      </div>
    );
  }
}

export default App;

Answer №1

Give this a shot:

.sidebar---_u0En{
  background: yourcolor
}

If it's still not working, try adding !important

OR

Your code might not be working because you're using background-color. Consider changing it to background

Answer №2

My solution involved adding an identifier

<SideNav
      onSelect={(selected) => {
        // Insert your code here
      }}
      onToggle={onToggle}
      id="sdb"
   >

To style it, I used the following in my CSS:

#sdb{
    background-color: #120A8F;
}

Answer №3

The SideNav component allows users to use a custom className, but there seems to be an issue with merging the classNames.

<SideNav className="menu" > ... </SideNav>

When using this code, your CSS styles defined in the .menu class are being overridden by the default classes of SideNav.

This problem can be traced back to this line of code.

To learn more about this issue, check out this discussion.

Answer №4

<NavigationPanel style={{'background-color': 'red'}}></NavigationPanel>

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

Can you explain which variable is considered global in Node.js?

Instead of writing var global = window for the browser I want my code to be able to work in a node environment as well. Something like var global = window || node_global What is node_global? I couldn't find any clear answer here: or here https ...

The npx command to create a new react-app doesn't seem to be functioning as expected

Encountered errors while running create react-app in the terminal. npx create react-app sample Error: EPERM: operation not permitted, mkdir 'C:\Users\Yasiru' TypeError: Cannot read property 'loaded' of undefined at exit ...

What is the solution to fixing the error message "SyntaxError: missing ) after argument list" in JavaScript?

I wrote some code in HTML/JavaScript/PHP, and in the 3rd echo statement, I added a button that calls the deleteAttribute() function when clicked. However, I encountered an error at the 3rd echo statement with (type = "button"): "Uncaug ...

Navigating tables with jQuery using a loop and extracting data from two tables with matching row names

I am facing a challenge with a function that combines data from two tables, each containing a column named "name". How can I specify which table's name should be displayed? function createTableRow(customers) { var data = JSON.parse(customers.resu ...

Is there a way to keep running npm start for reactjs even after closing the terminal?

I have been working through a Facebook tutorial using ReactJS. After installing npm install -g create-react-app from https://www.npmjs.com/package/react-scripts and creating the app, I am now confused about how to deploy it. For example, how do I deploy i ...

What is the best way to establish personalized CSS styles specific to each subdomain?

I am in the process of establishing a multi-tenant application with a single instance and single database setup. The backend infrastructure is built using Ruby on Rails, while the frontend is handled by a separate AngularJS app integrated with a Rails fram ...

Using the identical code, Wicked PDF generates distinct reports on separate computers

While utilizing Ruby on Rails to render a PDF using WickedPDF and sending it via email, I encountered an unexpected issue. The same code is present on two separate computers, both with up-to-date versions synced from GitHub. However, the generated PDF repo ...

How can we dynamically resize page content to fit varying browser window sizes across different devices with the help of jQuery/JavaScript?

Looking for a solution involving an HTML form that includes a text field and a submit button. The text field is where the user enters a URL, and upon clicking the submit button, they are redirected to that URL. Seeking a way to adjust the size of the new ...

My Node setup is not displaying my scene with the THREE.js Software Renderer

Struggling to incorporate 3d graphics into Node.js environment, I stumbled upon the Software Renderer after exhaustive research. The renderer is up and running, but I am facing difficulties in rendering my scene. The issue lies in the fact that my 3d obje ...

After starting the server, I am receiving a notification saying "Unable to retrieve /". Can anyone advise me on what I might be doing incorrectly?

I am encountering an issue while attempting to perform a GET request to fetch images from my Cloudinary account. Upon running the server, I am receiving a 400 status code on my UI with the message Cannot GET / How can I troubleshoot and resolve this pro ...

The Gusser Game does not refresh the page upon reaching Game Over

Hi there, I am a beginner in the world of JavaScript and currently working on developing a small guessing game app. However, I have encountered an issue where the page is not reloading after the game is over and the 'Play Again' button appears to ...

Retrieve the input field value using JavaScript within a PHP iteration loop

I've implemented an input box inside a while loop to display items from the database as IDs like 001,002,003,004,005 and so on. Each input box is accompanied by a button beneath it. My Desired Outcome 1) Upon clicking a button, I expect JavaScript t ...

Troubleshooting issues with Angular 2 HTTP post and Web API integration

Here is an example of my Web Api Core Controller Method: public void Post(Sample sample) { _sampleService.CreateSample(sample); } The Sample POCO is defined as follows: public class Sample : BaseEntity { public string BarCode { get; s ...

What is the best way to align social media icons at the center of the footer section?

I've been working on trying to center the social media icons in the footer, but no matter what changes I make in the code, there's been no visible difference. Can anyone offer some assistance? footer { background-color: #FFF; color: white; ...

Tips for preventing HTML ID clashes while integrating with the Document Object Model of external websites

When incorporating additional HTML elements into a webpage using Javascript or jQuery, along with external CSS declarations, it is important to avoid conflicts with existing IDs and class names already present on the page. This could lead to issues if ther ...

Transforming the string attribute of an object within a JavaScript array through mapping

Here is an array of objects: { "attr1": 123, "attr2": "a.end", }, { "attr1": 123, "attr2": "b.start", } The task is to remove the first part of the attr2 string up to and including the '.& ...

Content is not being contained within a div container

I'm facing a unique issue that I've never encountered before - text is not wrapping inside a div element. Here's a snippet of my HTML code: http://jsfiddle.net/NDND2/2/ <div id="calendar_container"> <div id="events_container"& ...

Rearranging the img element within the dom structure to optimize display in various blog posts

Hey there, I have a specific task that I need help with: Currently, I am using Business Catalyst as my framework. They have a blog module that does not offer much customization when it comes to blog lists. There is a preview tag that displays a preview of ...

React: Improve performance by optimizing the use of useContext to prevent unnecessary re-renders of the entire app or efficiently share data between components without causing all

In my app, I have a Header.tsx component that needs to be accessible on all pages and a Home.tsx component where most of the content resides. The Home.tsx component includes an intersectionObserver that utilizes the useContext hook (called homeLinks) to p ...

The children component is not recognizing the function being passed through this.props.children, resulting in an

Looking for a solution that involves passing a function to this.props.children? Check out the code snippet below: updateBarTitle(barTItle){ this.setState({barTItle}); } render(){ const children = React.Children.map(this.props.children, function (chi ...