Guide to adding a CSS class to an Ionic2 toast

i found a helpful resource on applying cssClass to my toast component.

within my HTML, I have buttons:

<button ion-button (click)="presentToast()"> toast</button>

Here is the code snippet from my .ts file:

presentToast() {
    let toast = this.toastCtrl.create({
      message: "Press again to exit",
      cssClass: "bottomToast",
      position: 'bottom'
    });

    toast.onDidDismiss(() => {
      console.log('Dismissed toast');
    });

    toast.present();
  }

In my app.css file, I specified the styles for `.bottomToast`:

.bottomToast{
    .toast-md .toast-wrapper {
        position: absolute;
        right: 0;
        left: 0;
        z-index: 10;
        display: block;
        margin: auto;
        width: 40%;
        max-width: 700px;
        border-radius: 35px;
        background: gray;
    }

    .toast-md .toast-message {
        padding: 19px 16px 17px;
        font-size: 1.5rem;
        text-align: center;
    }
}

Upon inspecting the toast element, I noticed the following structure was generated:

<ion-toast role="dialog" class="toast-md bottomToast" aria-labelledby="toast-hdr-0" style="z-index: 19999;"><div class="toast-wrapper toast-bottom" style="transform: translateY(0%);"> <div class="toast-container"> <!--template bindings={ "ng-reflect-ng-if": "Press again to exit" }--><div class="toast-message" ng-reflect-id="toast-hdr-0" id="toast-hdr-0">Press again to exit</div> <!--template bindings={ "ng-reflect-ng-if": null }--> </div> </div></ion-toast>

However, when I remove the `.bottomToast` class and use only `.toast-md .toast-wrapper` and `.toast-md .toast-message`, the toast functions correctly.

I must have made an error in defining the CSS rules within the `bottomToast` class. I need assistance getting the toast styling to work as intended.

Answer №1

It seems like your bottomToast is not the parent of toast-md. You may want to consider the following structure instead:

ion-toast.bottomToast.toast-md {
    .toast-wrapper.toast-bottom  {
        position: absolute;
        right: 0;
        left: 0;
        z-index: 10;
        display: block;
        margin: auto;
        width: 40%;
        max-width: 700px;
        border-radius: 35px;
        background: gray;
        /* color: black; */
    }

    .toast-md .toast-message {
    padding: 19px 16px 17px;
    font-size: 1.5rem;
    /* color: #fff; */
    text-align: center;
}
div#toast-hdr-0 {
    text-align: center;
}
}

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

When altering the value format, the input shows NaN

Inside a mat form field, I have an input: <mat-form-field style="padding-right: 10px;"> <input matInput type="text" [ngModel]="value | formatSize" (ngModelChange)="value=+$event"; placeholder="value" [ngModelOptions]="{standalone: true}"&g ...

Preventing angular mat-menu from closing when clicking outside of it: simple solutions

When implementing MatMenu as a popup for guiding new users on my web app, I prefer not to close it when the user clicks outside of it. I've successfully used $event.stopPropagation() to prevent closure when clicking a button within it. Now, I'm ...

Stop accidental form submissions on iOS devices by disabling the return button

In my Ionic 3 application running on iOS, I encountered a bug that allows users to submit a form even when the submit button is disabled. Despite trying different solutions from this source, I have not been successful in resolving it. To prevent accidenta ...

Is there a way to customize the scrollbar color based on the user's preference?

Instead of hardcoding the scrollbar color to red, I want to change it based on a color variable provided by the user. I believe there are two possible solutions to this issue: Is it possible to assign a variable to line 15 instead of a specific color lik ...

Angular: ChangeDetection not being triggered for asynchronous processes specifically in versions greater than or equal to Chrome 64

Currently, I'm utilizing the ResizeObserver in Angular to monitor the size of an element. observer = new window.ResizeObserver(entries => { ... someComponent.width = width; }); observer.observe(target); Check out this working example ...

Tips for refreshing the default style of Material UI select

I'm having trouble customizing the default background color of the first menuItem in the select component. The class I need is not visible when inspecting the element, as the background color disappears upon inspection. Steps to reproduce: 1. Click ...

Achieving text alignment with icons in Angular

I'm having trouble aligning my text with the icon next to it despite trying to adjust margins. I would really appreciate any help or suggestions on how to resolve this issue. <div class="notification" [ngClass]="{'no ...

How can you make the coordinates of the cursor track the cursor when it hovers over a rectangle?

The code provided below will constantly display the cursor's coordinates right below the cursor: function displayCursorCoordinates(e) { var x = event.clientX; var y = event.clientY; var coordinates = "(" + x + ", " + y + ")"; document.getEl ...

What methods can I use to dismantle an Angular component?

I have created a modal as a component called <modal-component>. Within the <modal-component>, there is a close button. I am looking for a way to completely remove the <modal-component> when this close button is clicked. I envision somet ...

Safari-exclusive: Google Maps API dynamically altering page aesthetics post-loading

Recently, I encountered a peculiar problem. Upon loading a page, the text displayed with full opacity. However, upon the Google Maps API loading after 2 seconds, the entire page's styling suddenly changed. It was as if the text on the page became less ...

Strategies for smoothly navigating the page to a specific div every time

Currently, I am working on a form that requires submitting multiple child forms. To enhance user experience, I have incorporated jQuery functionality to display a message at the top of the page upon each submission. Now, my goal is to implement a feature w ...

clicking on internal links in the bootstrap side menu causes it to jump

Im trying to add a side menu to a help page. The menu and internal links are functioning properly, but when clicked, the side menu partially goes behind the navbar. As a beginner, I'm not sure how to resolve this issue. Can someone offer some guidan ...

Step-by-step guide for serving static JavaScript files using NextJS

I am currently exploring the process of hosting static js and css files using NextJS. My journey began with creating a react app through create-react-app, where I developed an App component before executing the npm run build command. This resulted in the ...

"Troubleshooting: Why Angular2's ngOnChanges is not triggering with array input

I am currently using a ParentComponent to pass inputs to a ChildComponent. When the input is a number, the ngOnChanges hook successfully fires. However, when it's an array, the hook does not trigger. Could someone help me identify what I might be doi ...

Updating a value in an array in Angular using the same ID

I have an array of buildings that looks like this: const buildings = [ { id: 111, status: false, image: 'Test1' }, { id: 334, status: true, image: 'Test4' }, { id: 243, status: false, image: 'Test7' }, { id: 654, stat ...

What are the best methods for detecting devices in order to create customized CSS styles for iPad and Galaxy Tab?

Ensuring my web application is compatible with various devices is crucial. While I have created a common CSS for all mobile and tablet devices, it seems to be causing some problems specifically on the iPad. After finding a fix tailored for the iPad, I now ...

Ways to avoid redundancy in Gitlab CI/CD when utilizing multiple stages

Currently, my workflow involves utilizing gitlab CI/CD for deploying my angular app on firebase. This process consists of 2 stages: build and deploy. image: node:11.2.0 stages: - build - deploy cache: paths: - node_modules/ build: stage: bu ...

How can you block a specific drop-down choice in Angular 2?

TS FILE import { Component, ViewChild } from '@angular/core'; /** * @title Basic select */ @Component({ selector: 'select-overview-example', templateUrl: 'select-overview-example.html', styleUrls: ['select-over ...

I'm having trouble accessing the Angular application that is running inside a Docker container

I'm completely new to Docker, so please be patient with me. Here is my Dockerfile: FROM node:alpine WORKDIR '/app' COPY ./package.json . EXPOSE 4200 RUN npm i COPY . . CMD ["npm","start"] These are the commands I used: docker build -t an ...

Following the upgrade of Angular, the webpack module source-map-loader is encountering an error: "this.getOptions is not a function"

Currently in the process of constructing my angular project using webpack alongside source-map-loader to extract source maps, like this: module.exports = { // ... module: { rules: [ { test: /\.js$/, enforce: "pre&quo ...