Search code examples
reactjssassreact-css-modules

How to override child css class in parent react component using sass


Trying to change background color of Toast container, the code below suppose to make this. I dont know what I am missing but it doesnt work...

this is what I tried:

.toastError {
  margin-top: 15rem;// this works
  &.Toastify__toast--error {
    background: #bd362f !important;// this is is not...
  }
}

react component:

import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
..
return (
<ToastContainer position="top-center"
          className={styles.toastError}
          autoClose={4000}
          hideProgressBar={false}
          newestOnTop={false}
          closeOnClick
          rtl={false}
          pauseOnFocusLoss
          draggable
          pauseOnHover
        />

margin-top effect the component but cant change the color, the element looks like below in browser : enter image description here

What do I need to do make it work?


Solution

  • You use cssLoader with css modules, right? maybe you must mark .Toastify__toast--error as global. Scoping classnames in cssLoader

    .toastError {
      margin-top: 15rem;
    
      :global(.Toastify__toast--error) {
        background: #bd362f !important;
      }
    }