Having trouble replacing the default mui style with custom css

I'm having trouble overriding the default styles applied by Material UI with my custom CSS styles. Here's the code I have attached for reference. Can someone please help me figure out what mistake I am making or what I might be missing? Thank you in advance.

Code snippet from React .jsx file:

    import "./StreamDashboard.css";
    import { Button } from "@mui/material";
    
    const StreamDashboard = () => {
        return (
            <div className="stream_container">
                <Button className="config_button" variant="contained">
                    Edit Config
                </Button>
            </div>
        );
    };

    export default StreamDashboard;

CSS code from .css file:

    .stream_container {
       height: 100vh;
     }
     
    .config_button {
      color: black;
      background-color: yellow;
      border-radius: 10px;
      margin-top: 10px;
    }

Answer №1

My preferred method for importing styles is as follows:

I always use *.module.css to prevent any conflicts with class names

import styles from "./StreamDashboard.module.css";

Then in the code, you can do something like this (for example):

import styles from "./StreamDashboard.module.css";
import { Button } from "@mui/material";
const StreamDashboard = () => {
  return (
    <div className={styles.stream_container}>
      <Button className={styles.config_button} variant="contained">
        Edit Config
      </Button>
    </div>
  );
};

export default StreamDashboard;

The file StreamDashboard.module.css contains:

.stream_container {
 /* styles */
}

.config_button {
 /* styles */
}

In essence, you need to import the CSS styles with a name (in the example above, styles) and then access the classes using styles.css_class_name

className = {styles.your_css_class_name}

I hope this explanation is helpful.

Answer №2

Try this out and add !important at the end to override any style you need.

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

Issue with background repetition in CSS

I'm looking to stretch a background image along the left margin of my webpage. Here's the CSS I'm using: body, html{ height:100%; } #content{ background:url(../images/leftBorder.png); background-repeat:repeat-y; height:100% ...

Has makeStyles caused IconButton hover color not changing in MUI anymore?

Greetings, I have been searching for a way to modify the hover color of an IconButton. Unfortunately, the previously discovered solution no longer appears to be effective Here is my current progress in this Code-Sandbox ...

"What's up with this hover script? It seems to be malfunction

I created a hidden div and tried to display it with a hover effect on another div, but it's not working. Here's my code: <html> <head> <title> Welcome to FreeAppzToday </title> <style> #home {background: ...

I am having trouble retrieving the information stored in an Array of Objects. Specifically, I am having difficulty accessing and iterating through each object using a for

Is there a way to extract data from an API individually and retrieve data from an Array? let {Array}=jsonData fetch("https://apis.ccbp.in/city-bikes?bike_name" + search, options) .then(function(response){ return response.json(); }) .then(funct ...

Is there a way to simply send the data to the API endpoint without having Django allauth url fetching from react and calling the signup view form?

For my project, I am utilizing React as a standalone Single Page Application (SPA) that connects to a Django backend with allauth for authentication management. When I enter the URL on my local browser (192.168.86.28:8000/accounts/signup/ or 127.0.0.1:8000 ...

Encountering a SyntaxError: Unexpected token when trying to run a React application

I encountered an issue with console.log while running my react app Below is the useEffect portion of my app: useEffect(() => { const fetchData = async () => { const result = await fetch(`/api/foodies/${name}`); const body = await res ...

What sets apart a function that returns JSX from a class component?

Can you differentiate between creating a function that returns JSX and creating a class that extends Component? // ES6/7 Syntax const Banner = (()=>( <div> My Awesome Component </div> )); class Poster extends Component { render ...

What is the best way to trigger a function in React when a constant value is updated?

In my React application, I have 3 components. The parent component and two child components named EziSchedule and EziTransaction. Each component fetches its own data from an API. The data to display in the EziTransaction child component depends on the reco ...

What is the process for displaying a Bootstrap Icon on a webpage?

I recently started using Bootstrap and I'm in the process of creating a login screen for my app. I want to incorporate MDBIcons for Google, Twitter, and Facebook. I referred to the documentation provided at However, upon previewing my webpage, I enco ...

JavaScript Cursor-Based Auto Typing Tool

I want to develop a straightforward Javascript auto writer within an HTML page. Below is the code I have written: <html> <head> <style> #type { display: inline-block; } #cur { display: inline-block; ...

Is it possible to eliminate process.env.NODE_ENV using browserify/envify?

Currently, I am utilizing ReactJS through NPM and Browserify, but I am encountering difficulties while attempting to build it in production mode as mentioned in the readme. The code I have for setting up browserify is: var browserify = require('brows ...

Display a hyperlink within a material ui Drawer

Adding react-router links to Drawer has been a challenge for me. I attempted the following approach: <Drawer width={200} open={this.state.drawerOpen} docked={false} onRequestChange={this.toggleDrawer}> <Link to="/businesspartners"> &l ...

Tips for combining or removing letters from the existing content in an input field for editing todo items in Redux

At this moment, my focus is on implementing an edit feature for my to-do app. The issue I am facing is that it manages to retrieve the current value, but there seems to be a restriction on deleting or adding letters. You can refer to the first input field ...

How can you ensure that an element returns to its original position after being animated in jQuery?

I want to add some animations to my website using jQuery, but I lack the skills to create them from scratch. I have managed to copy some code snippets, but I am facing an issue with one of my animations. When I click a button, the block animates, but I wan ...

Customize the font style of TextField

I'm trying to customize the font for a TextField component in my project using @material-ui. Below is the code snippet for the TextField: <TextField id="outlined-basic" className={classes.inputField} hintText="Level Data" ...

Limiting functional component re-renders to only occur when certain states change

Is there a way to make a component re-render only when a specific state in that component changes, instead of re-rendering with every state change? Here is an example code snippet: suppose I have a component with three states and I want it to re-render on ...

What solutions are available to resolve the routing problem in React.js?

On my fourth day working with Node and React.js, I am creating a custom offline search function for Docusaurus 2. I've built a JSON index and implemented a search function using elasticlunr. My goal is to redirect to a separate results page, but I&apo ...

Having difficulties adjusting the margin for a JSX element directly within the code

I'm struggling with giving a margin style inline to a JSX element. Here's the code snippet that I'm having trouble with: <Nunito20 style={{color: frenchGray, margin: 20 0 3 0;}}>Full Name</Nunito20> Unfortunately, this is throw ...

Receiving a sleek black overlay with dynamic text upon hovering over an image

I have been searching extensively for a solution to my issue, but I haven't been able to make it work in my application. What I want is to create a black overlay over an image when it is hovered over, with text that resembles a button appearing on top ...

Can a create-react-app be created on a virtual private server (VPS)?

I am eager to begin working on a create-react-app project on a VPS so my client can monitor my progress. While I understand you can "Add React to a Website," I am unsure how to incorporate libraries into my site using the tutorial provided on the ReactJS ...