Personalize and modify Ngx-toastr in Angular 6 using TypeScript

Hello everyone, I am currently working on implementing Ngx-toastr in Angular 6 with Typescript. My main issue is that I am struggling to achieve the desired visual appearance because I'm uncertain about which CSS styles are overriding the ngx-toastr class. I have written some CSS in the Style.css file for ngx-toastr where I specified a border-radius of 15px, but unfortunately, the inner part is not displaying rounded corners as intended. Despite searching various online resources, I haven't been able to find a satisfactory solution. Making changes to other toastr components is not feasible for me due to the large number of components (350+) in my project. Therefore, I need to figure out a way to customize the existing toastr CSS.

Below is the CSS code snippet that I have used:

.toast-container .ngx-toastr {
    position: relative;
    overflow: hidden;
    margin: 0 0 6px;
    padding: 15px 15px 15px 50px;
    width: 300px;
    border-radius: 15px !important;
    background-position: 15px center;
    background-repeat: no-repeat;
    background-size: 24px;
    box-shadow: 0 0 12px #999;
    color: #fff;
    border-image-source: linerar-gradient(red,purple) !important;
    border: 4px solid green !important;
    border-image-source: linear-gradient(red, purple) !important;
    border-image-slice: 20 !important;
}

.toast-success {
    background-color: #51a351;
}

My objective is to replicate the design shown in this picture. You can see it by visiting this link and clicking on the RESET button to trigger the toastr notification here.

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

You can access my code on StackBlitz here.

Answer №1

By implementing these CSS overrides in your Style.css file, I successfully customized the appearance of ngx-toastr.

Important: Prior to overriding this CSS, make sure to inspect the toastr class using browser dev tools or element inspection.

.toast-container {
  background-image: linear-gradient(purple, red) !important;
  border-radius: 22px !important; 
  box-shadow: -5px 8px 16px 0px rgba(0,0,0,0.3) !important;
  margin-bottom: 2px !important;
}

.toast-container .toast {
  margin: 2px !important;
  box-shadow: none !important;
  border-radius: 20px !important;
  background-color: #fff !important;
}

.toast-success{
  background-image: none !important;
}

.toast-success::after{
  content: '\f00c' !important;
  font-family: 'FontAwesome' !important;
  position: absolute !important;
  top: 14px !important;
  left: 15px !important;
  color: #333 !important;
  font-size: 1.5em !important;
}

.toast-title{
  color: purple !important;
  font-size: 16px !important;
}

.toast-message{
  color:#8f8f8f !important;
}

Answer №2

To eliminate the white box shadow, simply apply the following code:

.toast-container .ngx-toastr {
  box-shadow: 0 0 12px #3b3b3b !important;
}

Answer №3

To get rid of the "border-image-source" in your CSS, simply remove it.

.toast-container .ngx-toastr {
    position: relative;
    overflow: hidden;
    margin: 0 0 6px;
    padding: 15px 15px 15px 50px;
    width: 300px;
    border-radius: 15px !important;
    background-position: 15px center;
    background-repeat: no-repeat;
    background-size: 24px;
    box-shadow: 0 0 12px #999;
    color: #fff;
    border: 4px solid green !important;
}

https://i.sstatic.net/7ErRm.png

If you want to create a custom toast according to your needs, you can do so by following this link:

https://github.com/scttcper/ngx-toastr/blob/master/src/app/pink.toast.ts

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

Simple and quickest method for incorporating jQuery into Angular 2/4

Effective ways to combine jQuery and Angular? Simple steps for integrating jQuery in Angular2 TypeScript apps? Not sure if this approach is secure, but it can definitely be beneficial. Quite intriguing. ...

Animating Page Transitions within Ionic 2

In my Ionic 3 application, I have a basic tabs template where I switch between tabs by swiping left or right. Everything works perfectly except there is no animation effect when transitioning between tabs either by tapping or swiping. I am able to achieve ...

Retrieve information from the app-root and transfer it to the component

<body> <app-root data="myData"></app-root> </body> I have added the myData at index.html and now I want to retrieve it to use in a component. What is the best way to access this data? Thank you. ...

What steps can be taken to ensure a successful request to a Node.js server when previewing an Angular app on a separate device within the same network?

My desktop computer hosts the Angular front-end on port 4200 and the Express.js back-end on port 4000. When I try to access the Angular app from my mobile Android phone using 192.168.1.X:4200, the app loads but doesn't display any data from the Expres ...

What are the recommended TypeScript tsconfig configurations for running Node.js 10?

Can someone provide information on the necessary target/libs for enabling Node.js v10.x to utilize async/await without generators? I have found plenty of resources for node 8 but not as much for node 10. ...

The checkbox state does not update dynamically in Angular 8 when the value of the form control is changed

I recently created a simple application that consists of a single checkbox and a button. The aim is to start a timer upon clicking the button, where every second the checkbox's state should toggle between checked and unchecked. To ensure the formCont ...

Angular - encountering challenges when implementing the native Web Speech API

My goal is to integrate the native Web Speech API directly without relying on any third-party libraries. I have successfully integrated the API into my service and voice recognition is functioning properly, able to generate text from recognized speech. Ho ...

The latest version of IntelliJ Idea Ultimate, 2023.2.5, does not offer compatibility with the updated control flow features in Angular

I recently made the switch to Angular 17 in my project and noticed that Idea is not recognizing the new syntax in HTML templates. <mat-menu #menu="matMenu"> @for (menuItem of getData().menu.items; track menuItem) { & ...

Issue encountered during rendering: "TypeError: Attempting to access property '_t' of an undefined object" while running a Unit Test using Jest

I spent hours troubleshooting a unit test for my Vue.js component, but no matter how much I searched the internet, I kept encountering this error: console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884 TypeError: Cannot read property ' ...

Implementing line breaks in Angular Template

I'm dealing with an angular page that includes a popup. The content of the popup is generated using the following code snippet: <div class="xs-12 form-group"> <div class="no-overflow" *ngIf="detail.Status; else em ...

Display excerpts of code within an Angular application within the HTML segment

I'm currently developing a tutorial page using Angular where I intend to display code snippets in various programming languages such as 'Java', 'TypeScript', 'C#', and 'Html'. Although there is a snippet called ...

Increase the ngClass attribute's value

Is there a way to automatically increment a numeric value in a class using the ngClass directive? For example, can we achieve something like this: <some-element [ngClass]="'class-*'">...</some-element>, where the asterisk (*) will in ...

The TS2583 error in TypeScript occurs when it cannot locate the name 'Set' within the code

Just started my Typescript journey today and encountered 11 errors when running tsc app.ts. Decided to tackle them one by one, starting with the first. I tried updating tsconfig.json but it seems like the issue lies within node_modules directory. Any help ...

What is the best way to save Azure Service Bus Message IDs with a package-internal type of 'Long' in MongoDB?

Currently, I am utilizing Azure Service Bus (@azure/service-bus) within a TypeScript-based nest.js service to schedule messages for delivery at a future date. In case the need arises, I must also have the ability to cancel these scheduled messages before t ...

Tips for transferring photos with Angular 5 and Node.js

What is the process for uploading images with angular 5 and node js? ...

Limiting the use of TypeScript ambient declarations to designated files such as those with the extension *.spec.ts

In my Jest setupTests file, I define several global identifiers such as "global.sinon = sinon". However, when typing these in ambient declarations, they apply to all files, not just the *.spec.ts files where the setupTests file is included. In the past, ...

Display the length of the product array when I have multiple JSON objects

I am working with the following JSON data: { "StatusCode": 0, "StatusMessage": "OK", "StatusDescription": [ { "_id": "12123", "dateCreated": "2019-12-03T13:45:30.418Z", "pharmacy_id": "011E7523455533 ...

MUI Select component not displaying top border

Can anyone help me understand why the select field is behaving this way? I'm new to the project and suspect that someone may have made changes to it. https://i.sstatic.net/pB6Sx.png <mui.FormControl style={{ width: '598px' }}> ...

Is there a way to programmatically control a Bootstrap Dropdown in Angular?

Need help with opening and closing a Dropdown in my View using my typescript class. Any suggestions on how to achieve this? Appreciate any assistance! <div ngbDropdown class="d-inline-block"> <button class="btn" id=&quo ...

Adapting imports in Typescript for seamless npm distribution

Currently, I'm facing an issue with module resolution while compiling my NPM package written in Typescript for publishing. In my project, I've been using non-relative imports to avoid the hassle of excessive ../../../. However, according to TypeS ...