The Navbar is not displaying the React Bootstrap 4 CSS module as intended

Having some trouble changing the color of my navbar. Is there a step I might be missing?

Here's the component I'm trying to render:

import React from 'react';
import { Nav, Navbar } from 'react-bootstrap';
import styles from './MainMenu.module.css';

const Topbar = () => {
    return(
        <Navbar className={styles.mainBar}>
          <Navbar.Brand>Restaurant</Navbar.Brand>
          <Nav.Link>Menu</Nav.Link>
        </Navbar>
    );
}

export default Topbar;

This is the CSS module being used:

.mainBar{
    background-color: rgb(255, 153, 0);
}

Below are the dependencies listed in the project's package.json file:

"dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "bootstrap": "^4.6.0",
    "react": "^17.0.2",
    "react-bootstrap": "^1.6.1",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.2"
  }

Bootstrap is correctly applied as it was imported into index.js...

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
reportWebVitals();

Answer №1

When importing a CSS file into your project's styles, it's important to note that unlike JS modules which export functions or objects, CSS files do not export anything. Simply remove "styles" from your import statement and just reference the CSS file directly like this:

import './MainMenu.module.css';

Then, in your JSX code, include the class name without any additional qualifiers:

<Navbar className="mainBar">

Following these steps should work correctly.

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

What could be causing the intersection observer to not accurately observe the second element?

Check out this example on codesandbox: https://codesandbox.io/s/quirky-wozniak-3qih8p?file=/src/Progress.tsx I'm currently working with the Intersection Observer API to monitor both the first and last elements in my list. My aim is to show either a l ...

Dynamic Hero Banner

As I work on creating a basic website for my football team, I am facing an issue with the text placement in different screen sizes. While the Jumbotron background image resizes perfectly according to the screen size, the text outside of the Jumbotron doesn ...

Craft a function within the recompose library

As I was exploring the compose function in recompose library by @acdlite to combine boundary conditions for Higher Order Components, I came across two different implementations of the compose function: const compose = (...funcs) => funcs.reduce((a, b) ...

How to line up two blocks side by side in a single block with Bootstrap without the use of CSS

The bootstrap margin is causing issues with this code <div class="row"> <div class="row1 col-lg-3"> <div class="row2 col-lg-1"></div> <div class="row2 col-lg-1"></di ...

The transformation from CSS and HTML to RoR resulted in sprites being converted into mysterious black boxes

Previously, this site was functioning fine without Ruby on Rails. However, after moving the code to Rails, a strange issue has arisen where the hover images turn black when the mouse is placed over them. // Place all the styles related to the home control ...

The Bootstrap navigation bar is experiencing issues and is not functioning properly, as the classes are not

<nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" d ...

How to automatically set a pre-selected value in a ReactJS Material-UI Select Component

Is there a built-in event in Material-UI for detecting changes in pre-selected values within a Select component? Take, for instance, this Select component with three options: https://i.stack.imgur.com/CKJ5C.png I am looking for an event that triggers wh ...

How can we determine the dimensions of an absolutely positioned element within a relatively positioned element?

One thing I noticed is that when placing an absolutely positioned element within a relatively positioned element, the latter does not automatically inherit the width and height of the former unless manually set. Take this example: <!DOCTYPE html> ...

Using various images in ReactJs Slick for mobile devices is a simple process that can greatly enhance

How can I implement a different mobile image in react slick slider compared to desktop mode? While I can use display none for breakpoints, I am curious if there is an alternative approach to achieve this. const Hero = () => { const classes = useStyle( ...

Issue with Materialize Sidenav: Not functional on iOS devices including iPhones, functions correctly on all other devices

My Materialize Sidenav is functioning on all devices except for iPad and iPhone. If you want to check out the code, here is the link to the repository: repo. Take a look at index.html (line 44 down) and js/onloadSetup.js. I attempted adding this in onload ...

The css-loader in Webpack fails to recognize the localIdentName option

Currently, I am utilizing the css-loader as a Webpack plugin to modify my CSS class names. However, I am facing an issue where the localIndentName option is not having any effect. Below is the snippet of my webpack configuration related to the css-loader: ...

Is it possible to modify or delete the question mark in a URL?

Currently, I am working on implementing a search bar for one of my websites hosted on Github. Below is the code I have written for the search bar: <!-- HTML for SEARCH BAR --> <div id="header"> <form id="newsearch" method ...

Countdown component in Ant Design failing to display correct date

I’m currently working on developing a specific date component using react in conjunction with antd. Below is the code snippet I am utilizing: import { Statistic, Col, Row } from 'antd'; const { Countdown } = Statistic; const deadline = Date.pa ...

Unlock the power of jQuery to apply CSS transition effects and animations with precision

A web application utilized Bootstrap, featuring a toggle navigation for the sidebar drawer/navigation that was supposed to be animated by default. However, there appeared to be no animation happening. To address this issue, the following CSS code was imple ...

The translation feature in React does not seem to be functioning properly with SASS

After trying various display settings like flex and block without success, I realized that the transform property was not working as expected. Despite centering elements successfully using other methods, the transform doesn't seem to have any effect o ...

What sets apart the implementation from the Three.js demo?

Attempting to replicate the provided example using react-three-fiber. Example link: https://github.com/mrdoob/three.js/blob/master/examples/webgl_lines_sphere.html (currently only implemented the init method, no animation) Here is my code: const Sphere = ...

Ways to simultaneously apply fade in and fade out effects using CSS

body { background-image: url("background.jpg"); background-attachment: fixed; font-family: 'Roboto', sans-serif; color: #333333; } #container { height: 1000px; } /* HEADER WITH NAVIGATION BAR AND LOGIN OPTION */ #head { position: abso ...

The HTML image link is adorned with a tiny blue checkmark underneath

My a tag with an image inside seems to be extending below the image, resulting in a small blue tic mark on the bottom right side. I've attempted different CSS solutions such as setting border to none, but nothing has resolved the issue. Any assistance ...

Testing React-hook-form with dynamic fields for validation is a breeze!

I am working on a React project with dynamic fields created using React-hook-form. I need to implement validation for these fields, specifically for children's names that should not be empty when the user clicks the 'Add' button. Parent com ...

Selecting multiple default values in a Material UI Radio button group

<RadioButtonGroup name={currentQuestion.id.toString()} onChange={this.onRadioBtnClick} valueSelected={answerObject ? answerObject.answer : ''} > Hi there! I have a question about the valueSelected prop in the RadioButtonGroup. ...