TyForHelpDude
TyForHelpDude

Reputation: 5002

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?

Upvotes: 0

Views: 2576

Answers (1)

Martin
Martin

Reputation: 6154

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;
  }
}

Upvotes: 5

Related Questions