Tips for altering the icon fill color in toastr notifications

I have customized toastr success and error messages in my application by changing the background and font colors. Now, I want to update the colors of the icons displayed in these messages. Despite my thorough search, I have been unable to find a way to modify the fill color of the icons or replace the icons altogether. Below is a screenshot of the success message: https://i.sstatic.net/ct317.png

Here is the screenshot for the error message:

https://i.sstatic.net/CUVZF.png

I aim to alter the icons within these messages or adjust the filling color of the icons. The JavaScript code snippet is as follows:

.success(function(data) {
     toastr.success('Successfully Build ', 'Congratulations!', {
                        closeButton: true
                    });
}).error(function(err) {
    toastr.error('Cant Build', 'Error', {
                        closeButton: true
                    });

In the CSS file:

#toast-container > .toast-success {
    background-image: none;
    background-color: #e9e9e9;
    color: black;
}
#toast-container > .toast-error {
    background-image: none;
    background-color: #e9e9e9;
    color: red;
}

Answer №1

Toaster utilizes small background PNG images (24x24 pixels) as icons, so the most effective solution is to replace them with a custom colored version you have created in advance.

For example, if you have a black checkmark PNG of the same dimensions ready, the CSS code would look like this:

#toast-container>.toast-success {
background-image: url(<insert the URL for your new PNG here>)!important;
}

If you need help crafting the icon in your desired color, consider visiting a website like flaticon.com for royalty-free icons in the size and color scheme you desire.

Answer №2

Implement this code snippet for a crimson heart effect

app.css

#alert-box > .alert-success:before {
    content: "\f004";
    color: crimson;
}

Answer №3

Styling with CSS


        #toast-container > .toast {
            background-image: none !important;
        }

        #toast-container > .toast:before {
            position: relative;
            font-size: 24px;
            line-height: 18px;
            float: left;
            margin-left: -1em;
            color: #FFF;
            padding-right: 0.5em;
            margin-right: 0.5em;

        }
        #toast-container .toast{
            background-color: #1b75bc !important;
        }
        #toast-container> .fa-check , .toast {
            background-color: #328b17 !important;
        }
        #toast-container> .fa-trash , .toast  {
            background-color: #590619 !important;
        }

        .toast-message{
            font-family: Calibri;
        }

Implementing JS


          toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": false,
            "progressBar": true,
            "positionClass": "toast-top-right",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "3000",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "300",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut",
            iconClasses: {
                error: 'fas fa-trash',
                info: 'fa fa-info',
                success: 'fas fa-check',
                warning: 'something',
            },
        };

https://i.sstatic.net/5wPwu.png

Answer №4

Although this question may be outdated, I have come across a more efficient solution that does not require altering the existing toastr templates icons. If you wish to keep the current icon for 'toastr-success' but want to create new templates with different icons, you can achieve this by specifying an icon class in the JavaScript:

toastr.info("Click To Open", "more text",{iconClass:"toast-custom"});

Simply define the CSS for "toast-custom" as follows:

 /* custom icon for toastr */
 #toast-container > .toast-custom {
    content: "\f00C";
}

/* custom style for toastr */
.toast-custom {
    background-color: purple;
}

I trust that this workaround proves to be useful for you!

Answer №5

Utilize the background image stored in the project directory

    #toast-container > .toast-success {
      background-image: url("../src/icon-success.png");
      background-color: #ffffff;
      color: rgb(22, 192, 62);
    }

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

How can I apply and delete a css class only while scrolling in a React application?

Currently, I am designing a pretend blog layout to showcase my work. The grid of posts features cards that are precisely 400x400 in size with a hover effect that magnifies and adds a drop shadow (this is visible in the dashboard route). However, an issue ...

AngularJS utilizes the $window object in directive code

Just when I think I have a handle on AngularJS, I hit a roadblock. In my application, I have multiple Google maps where users can click on markers to view more information on a new screen. Everything is working smoothly until I try to navigate to the new ...

css Apply styles to form controls only if they are not empty

Utilizing an angularjs form, I have customized the following example to fit my code: .my-5 { margin:100px; } .form-group { position: relative; margin-bottom: 1.5rem; } .form-control-placeholder { position: a ...

What methods can be used to differentiate between value equality and reference equality when watching something?

In the world of AngularJS, the $watch function comes with an interesting twist - it has an optional third parameter. By default, this parameter is set to false, which means the watch will only trigger if the watched reference changes. But if you set it to ...

Issue with date range filter functionality not functioning as expected

Struggling to get the date range filter to function properly. Selecting a date triggers it, but nothing is being added to the var filter. I've spent hours trying to solve this issue with no progress. html <div class="form-group"> <input ...

What is the best way to format or delete text enclosed in quotation marks within an anchor tag using CSS or JavaScript?

I have encountered an issue with a dynamically generated login form. When I select the 'Forgot Password' option, a new 'Back to Login' message appears along with a separating '|' line. Removing this line is proving challenging ...

Set a CSS rule to style every other row in a table, starting from the second row and resetting after

Is there a way to refresh the even and odd count in CSS whenever a specific row is shown? Here's an example setup: header header header even even even odd odd odd Subhead Subhead Subhead even even even How can I ensu ...

What is the best way to integrate images into the Shopify source code?

Looking for assistance here. I've been working on my theme in vscode and added a new section that is very simple (just text and an icon). It's working perfectly fine in Shopify cli. But when I tried to implement it on my Live theme, the icons ar ...

jQuery Animation: Creative Menu Icon Display

Whenever the toggle menu's navigation icon is clicked, it triggers an animation that transforms the "hamburger" icon into an "X", causing the navigation menu to drop down. If a user clicks either the navigation icon or outside of the active toggle me ...

Creating an overflow effect for sliders using only CSS

Is it feasible to develop a slider that extends beyond its parent elements and the body? The concept involves having content within a section housed in a container. The slider would be part of this section, with slides overflowing past the parent element ...

HTTP GET request not updating data

I'm experimenting with AngularJS and trying out some examples: Here's the HTML code snippet: <html ng-app="myApp"> <body ng-controller="JokesController"> <h1>{{ joke }}<h1> </body> </html> A ...

What is the best method for incorporating CSS into an Angular application's embedded PowerBI report, which is displayed

Is there a way to incorporate external CSS or another method to apply styles to a PowerBI report embedded in an Angular application as an iframe? Specifically, I want to remove the scrollbar to ensure that the report seamlessly fits within the angular page ...

Guide to downloading Excel file using AngularJS and RESTful API

Code Snippet for Angular JS: $scope.getExcelDownload = function(index,basketid,brokerid,tradeDate,serverid,transid) { var myformid = 'ExcelForm' + index; ExcelDownload.get({brokerid : brokerid,basketName : basketid,appl : &ap ...

Troubleshooting a Navigation Styling Issue in HTML and CSS

I'm struggling to position my drop-down menus correctly in my WordPress theme navigation. They are appearing far away from the nav bar and end up near the top left corner of the screen when I hover over a ul li >. Here is the CSS code I am using: ...

Customizing the appearance of two separate tables

I have a pair of tables that I want to style differently. Table 1 needs the images centered with no border, while table 2 should have text left-aligned with a border. Here is the CSS: table, th, td { border: 1px solid #999; border-collapse: colla ...

instructions for creating a hover effect where one div vanishes when hovering over another div

Is there a way to make the line visible when hovering over my circular div? #line { display: none } <div id='circle'> <div id= 'line'> ...

How can the backgroundImage css in react admin <Login /> be replaced using Material-UI?

I have been refering to the following resources: Learn about customizing login page background in React-Admin: Explore themes customization in Material-UI: https://material-ui.com/customization/components/ Instead of using a preset background, I want to ...

The <Button> element is incompatible with popups. (HTML, CSS, JS)

I've been struggling with this issue. I used CSS color values to create a smiley face, but when I added a button it messed up the design (adding an unwanted circle around the center of the smiley). I attempted to synchronize the button tag with the po ...

What are some ways to customize the appearance of React Semantic components?

Is there a way to apply CSS for react semantic UI when using create react app? I have installed semantic-ui-react and included the CSS CDN: loginForm.js: import React from "react"; import { Button, Form, Header } from "semantic-ui-react"; import styles f ...

Is it permissible for H2 heading to resemble H1 visually, and vice versa, in compliance with WCAG guidelines?

My expertise lies in Accessibility testing. Currently, we are dealing with Two headings <h1 class="CssPropertywithSmallFontSize">Heading One</h1> <h2 class="CssPropertywithBiggerFontSize">Heading Two</h2> From a visual standpoint, ...