saurabh saurabh - 1 month ago 46x
AngularJS Question

How to show md-toast with background color

I am trying to create md-toast with having some background color to toast using angular-material. I using answers from this SO question, I created this codepen, but it is showing some unwanted background to toast as well.


<div ng-controller="AppCtrl" layout-fill="" layout="column" class="inset toastdemoBasicUsage" ng-cloak="" ng-app="MyApp">
Toast is not properly working with theme defined in CSS.

<div layout="row" layout-sm="column" layout-align="space-around">
<md-button ng-click="showSimpleToast()">

CSS: {
background-color: green;
} {
background-color: maroon;
position: 'top right'

md-toast {
height: 40px;
width: 50px;
margin-left: auto;
margin-right: auto;
left: 0; right: 0;


angular.module('MyApp',['ngMaterial', 'ngMessages'])
.controller('AppCtrl', function($scope, $mdToast, $document) {
$scope.showSimpleToast = function() {
.textContent('Simple lala Toast!')


Positioning the toast

Instead of giving a position to everything (which makes the cutting of your toast), you can position only the md-toast to the right position.

By the documentation, there are four location were you can officially put the toast: top left, top right, bottom left, bottom right. So, first, lets position the toast to top left (this is important for the change in animation. Also, this will allow us to show toasts on bottom center as well).

    .textContent('Simple lala Toast!')

now, in the css, just position your toast:

md-toast {
  left: calc(50vw - 150px);

This will position the toast at the center of the viewport, minus half of the toast.

you can also show toasts on the bottom center by javascript alone:

    .textContent('Simple lala Toast!')

and the toast will center at the bottom and use the right animation to show it.

Coloring the toast

You colored the toast's container instead of the actual content of the toast. To color the toast, you can add the following css styling: .md-toast-content {
  background-color: green;

Here's a working FORK of you codepen.