Ngx-toastr: How to add a custom class without replacing 'toast'?

Created on 7 Dec 2018  路  11Comments  路  Source: scttcper/ngx-toastr

Sorry if this is answered somewhere, but I want to add some custom styles to an individual toast popup (e.g. increase width). I see the toastClass config option - but this replaces the toast class which has essential styles applied to it (from bootstrap styles).

Is the only way to copy all the styles attached to .toast into my own custom class?

Most helpful comment

i had success by being more specific with the classes. could also try !important.

.yourclass.toast-success {
  background-color: blue;
}

All 11 comments

In CSS you can add your own .toast class and add/override any CSS properties that you want.

@yarrgh Thanks, but that would apply to all my toasts. I'm wondering if I can target one specific toast (that is displaying HTML content) without affecting other toasts and without having to copy all the styles that are attached to the toast class.

I 2nd this. it would be very convenient to simply add styling in addition to the defaults. Copying all styles to a custom class still introduces errors for me such as the onTap and onAction events no longer firing

This is a much-needed feature.
I need to show popups of different colours and one way to do that is, extend Toast component like in pink toast example but in my case, I would have to create 10 different custom components.

if there is any other way please let me know.

Thank you

put 'yourclass ngx-toastr' for toastClass?

@scttcper Thank you for the quick reply.

I tried adding my class with the property of background-color and toast class but it shows a toast with transparent background with no padding also closebutton and onTap action are not working.

However, if I use toastClass:my-class ngx-toastr`` it gives me a black toast but the rest of the properties are what I want.

Can you please suggest how can I use it in the correct manner.

Thank you very much in advance :)

i had success by being more specific with the classes. could also try !important.

.yourclass.toast-success {
  background-color: blue;
}

Thank you very much 馃憤

I have this working with the css you provided and then specifying toastClass: 'ngx-toastr toast-success yourclass'

As you can see I had to use both ngx-toasts and toast-success to make it work.

One more quick question, please.

I have to put my class in styles.css. I would want to move it to the component level css file, its the place I am calling toasterService.show() from. Is it possible to do so?

Once again thank you for the help!

the toast is not inside the context of your component so scoped css would not be applied. custom toasts would be the closest you could get but would still require positioning styles applied globally

Is there any way I can change the position of the toastr from within a component? I see the toastClass gets applied to the content, not the container.

i had success by being more specific with the classes. could also try !important.

.yourclass.toast-success {
  background-color: blue;
}

This worked like charm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

picninim picture picninim  路  6Comments

quirogamauricio picture quirogamauricio  路  3Comments

crhistianramirez picture crhistianramirez  路  5Comments

Nagenderpratap picture Nagenderpratap  路  4Comments

wa1gon picture wa1gon  路  6Comments